[ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]
Article: 11058 of comp.protocols.kermit.misc
From: email@example.com (Frank da Cruz)
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 inc