next up previous contents
Next: Searching Directories Up: Basic Directory Commands Previous: Creating Directories

Removing Directories

Directories can be removed in two ways. The rmdir command removes directories that are empty, while the rm -r command recursively removes all files and subdirectories within the directory specified, then it removes the target directory itself:

rmdir directoryname

rm -r directoryname

Be EXTREMELY careful when using recursive file removal! It is very easy to remove files with the -r option. If you don't pay attention to the directory that you are in, it is possible to delete ALL of your files by accident with this command. Because of this, the rm command has an option -igif that will cause rm to ask you for removal confirmation for EVERY file in the directory tree. rm should be aliased to rm -i to prevent accidental deletion of files.

Another useful option of rm is -f. The -f option forces deletion of files that are write-protected. This can be very useful to prevent a never-ending string of ''override protection xxx for file yyy'' messages when removing files recursively. Again, use of the -f option can be very dangerous.



Larry Latour
Fri Sep 12 08:12:59 EDT 1997