[ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]
Article: 11058 of comp.protocols.kermit.misc
From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
Newsgroups: comp.protocols.kermit.misc
Subject: Case Study #15: File Selection
Date: 24 Jan 2000 23:23:30 GMT
Organization: Columbia University
A question we see posted on the newsgroups at least once a week is "How do I delete files more than a week old?" Of course each operating system might (or might not) have its own way of doing this; some straightforward (like VMS's DELETE /BEFORE command), some not so obvious:
find directoryname -type f -mtime +7 -print | xargs rm
This is just one example of a larger class of problems: "how can I select files for a particular action?".
C-Kermit 7.0 handles file selection in two ways: first by incorporating the notion of "switches" into its command language, and second by its new, more-powerful wildcard syntax. We might discuss wildcards another time (it's about what you get in csh or bash) but you can find out all about it any time by typing "help wildcard" at the C-Kermit prompt.
Switches (command modifiers) should be familiar to anybody who has used the command languages of DOS, VMS, TOPS-10 or TOPS-20, RT-11, RSX-11, AOS/VS, and so on. Switches are optional keywords that begin with a slash (/) and might also take an argument. For example:
delete /before:-1week *.log
Here "delete" is the command, "/before:" is the switch, "-1week" is the switch argument, and "*.log" is the target of the command. This deletes all files whose names end with ".log" in the current directory that are more than a week old.
Let's see what other switches are offered by Kermit's DELETE command:
C-Kermit>delete ? File specification; or switch, one of the following: /after: /except: /noask /not-after: /ask /heading /nodotfiles /not-before: /before: /larger-than: /noheading /simulate /dotfiles /list /nolist /smaller-than: C-Kermit>delete
The name of each switch should be suggestive of its function, but of course you can type "help delete" for a description of each switch.
The switches that are listed with a terminating colon (:) take arguments. You can find out what the argument is by typing a question mark after the colon:
C-Kermit>delete /before:? File-time C-Kermit>delete /except:? Pattern
The /BEFORE, /AFTER, and related switches accept dates and/or times, which can be given in almost any format that is not ambiguous, and you can also give relative dates like "yesterday", "-12days", and "+2weeks".
The /EXCEPT switch lets you enter an exception list: one or more filenames or patterns that should be excluded from the operation.
Here's an example:
delete /dotfiles /before:-1week /larger:10000 /except:*keep* *.log
This deletes all files, including dotfiles (like ".readme"), whose names end with ".log" that are more than a week old and larger than 10000 bytes, except the ones whose names include the word "keep".
In case you're unsure of yourself, you can include the /SIMULATE switch, which tells C-Kermit to list the files it WOULD have deleted without actually deleting them.
Of course file-selection (and other) switches are not only for the DELETE command. Most of C-Kermit's file transfer and management commands now have switches; for example, the SEND command:
C-Kermit>send ? Filename, or switch, one of the following: /after: /except: /nodotfiles /recursive /array: /filter: /not-after: /rename-to: /as-name: /filenames: /not-before: /smaller-than: /before: /larger-than: /pathnames: /starting-at: /binary /listfile: /print: /subject: /command /mail: /protocol: /text /delete /move-to: /quiet /dotfiles /nobackup /recover C-Kermit>send
Or the new PURGE command, for managing those annoying backup files:
C-Kermit>purge ? Filename or switch, one of the following: /after: /heading /nodotfiles /not-before: /ask /keep: /noheading /page /before: /larger-than: /nolist /recursive /dotfiles /list /nopage /simulate /except: /noask /not-after: /smaller-than: C-Kermit>purge
Or the new built-in DIRECTORY command:
C-Kermit>dir ? File specification; or switch, one of the following: /after: /englishdate /noheading /recursive /all /except: /nomessage /reverse /array: /files /nopage /smaller-than: /ascending /heading /norecursive /sort: /backup /isodate /nosort /xfermode /before: /larger-than: /not-after: /verbose /brief /message: /not-before: /directories /nobackup /noxfermode /dotfiles /nodotfiles /page C-Kermit>dir
You can use switches in any desired combination to obtain results you couldn't get before. Returning to our original example, let's say that rather than deleting files that are more than a week old, we want to move them to another computer. Assuming the connection is already made and the other Kermit is in server (or receive) mode, the command is deceptively simple:
send /delete /before:-1week *.*
But remember all that's going on behind the scenes:
And so on; most of this has been covered in previous installments.
To read all about switches, see Section 1.5 of the C-Kermit 7.0 Update Notes. Date/time formats are explained in Section 1.6. The DIRECTORY command is described in Section 4.5.1 and the DELETE and PURGE commands in Section 4.5.4. File-transfer command switches are documented in Section 4.7. The new wildcard syntax is covered in Section 4.9.
- Frank
[ Top ] [ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]
C-Kermit 7.0 / Columbia University / kermit@columbia.edu / 24 Jan 2000