14.8. Safer File Deletion in Some DirectoriesUsing noclobber (Section 43.6) and read-only files only protects you from a few occasional mistakes. A potentially catastrophic error is typing: % rm * .o instead of: % rm *.o In the blink of an eye, all of your files would be gone. A simple, yet effective, preventive measure is to create a file called -i in the particular directory in which you want extra protection: ./- Section 14.13 % touch ./-i In this case, the * is expanded to match all of the filenames in the directory. Because the file -i is alphabetically listed before any file except those that start with one of the characters !, #, $, %, &, ', ( , ), *, +, or ,, the rm command sees the -i file as a command-line argument. When rm is executed with its -i option, files will not be deleted unless you verify the action. This still isn't perfect, though. If you have a file that starts with a comma (,) in the directory, it will come before the file starting with a dash, and rm will not get the -i argument first. The -i file also won't save you from errors like this: % rm [a-z]* .o If lots of users each make a -i file in each of their zillions of subdirectories, that could waste a lot of disk inodes (Section 14.2). It might be better to make one -i file in your home directory and hard link (Section 15.4) the rest to it, like this: % cd % touch ./-i % cd somedir % ln ~/-i . ... Second, to save disk blocks, make sure the -i file is zero-length -- use the touch command, not vi or some other command that puts characters in the file. -- BB Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|