Monday, May 15, 2006

FIND (Unix Command)

The “find” command is a very powerful and useful tool. Here are just a few examples to wet your taste buds with:

The below command will give you a list of all files over a gig in size. Just change the '/u01/' to look at what ever mount point is appropriate.

find /u01/ -size +1048576000c -print

The output can be redirected from standard output to a file by appending the following to the end of the command:

>/directory/path/file_name.txt

If you want to remove all files in a directory and its sub-directories, move to the starting directory and execute the following command:

cd /u01/directory_name/
find . -name '*.txt -mtime +32 -exec rm -f {} ";"

This will remove all *.txt files 32 days or older. A ‘oops’ to watch out for, is that some OS’s such as AIX tend to not always update the timestamp on a file when it is moved into another directory such as one being used for archiving. For example; if you just moved a file into a directory you have identified for archival purposes and the timestamp is say, 64 days old on the file in question and it is not re-stamped during the “mv” command and you run this “find” example, that file will be removed. This would be a bad thing if your backup routine had not executed on that file yet. Just a little something to keep in mind.

No comments: