14.19. Using find to Clear Out Unneeded FilesDo you run find on your machine every night? Do you know what it has to go through just to find out if a file is three days old and smaller than ten blocks or owned by "fred" or setuid root? This is why I tried to combine all the things we need done for removal of files into one big find script:
2>&1 Section 36.16
This is an example of using a single find command to search for files with different names and last-access times (see Section 9.5). Doing it all with one find is much faster -- and less work for the disk -- than running a lot of separate finds. The parentheses group each part of the expression. The neat indentation makes this big thing easier to read. The -print -exec at the end removes each file and also writes the filenames to standard output, where they're collected into a file named /tmp/.cleanup -- people can read it to see what files were removed. You should probably be aware that printing the names to /tmp/.cleanup lets everyone see pathnames, such as /home/joe/personal/resume.bak, which some people might consider sensitive. Another thing to be aware of is that this find command starts at the root directory; you can do the same thing for your own directories. --CT and JP
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|