Get Rid of Old IFS Files, Take Two
December 6, 2002 Timothy Prickett Morgan
Hey, Ted:
I have worked with Unix for 18 years. Here is a Qshell command that will remove any file that is more than seven-days old. (It also checks subdirectories).
Here is the command:
find * -type f -mtime +7 -exec rm {} ;
— Mike
|
I am grateful to Mike for providing that tip.
Now, let’s break that command down so we can understand it.
The find command locates files that match certain criteria. In this case, find looks for files that have not been modified in the last seven days.
The find command may be followed by options. In this example, no options are specified.
After the options comes the name of the file(s) to be searched. The asterisk (*) is a wildcard symbol meaning all files in the current directory and any subdirectories under the current directory are considered for selection.
The -type, -mtime, and -exec tokens are called primaries. The values that follow each of them are called operands. Together they form an expression that tells find which files to select.
A -type of f means that find is to search for regular files. A -mtime of +7 means that find is to look for files that have not been modified in seven days. The -exec primary indicates the action that find is to take when it selects a file. In this case, find is to run the rm (remove file) utility. Find replaces the empty braces with the name of the selected file.
I am very cautious when it comes to deleting things, so if you want to play with this command, I suggest you replace rm with echo, as in this example:
find * -type f -mtime +7 -exec echo {} ;
Find will list the names of the files instead of removing them. Do not replace echo with rm until you are certain that find locates the files properly.
To learn more about the find utility, visit the iSeries Information Center’s Find files Web page at http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/rzahz/find.htm . For another example, see “Grepping it Up“, in the January 11, 2002, issue of Midrange Guru.
— Ted
Sponsored By ADVANCED SYSTEMS CONCEPTS |
Business Analytics SEQUEL FYI
User Quote: SEQUEL FYI offers outstanding OLAP business intelligence functionality for a fraction of the cost of comparable solutions. |