Unix includes two commands that you can use to delete files and directories: rm (remove) and rmdir (remove directory).
Warning!
rm may be the most dangerous command in Unix. Because Unix doesn't have a Trash that lets you recover mistakenly deleted files, when you delete a file, it's gone forever.
There are two options that you may want to use with the rm command:
-i tells the rm command to ask permission before deleting each file (Figure 24 ). You must press
rm command in action, with and without the
-i option.
-R, which stands for
recursively , tells the rm command to delete everything within a directory, including its sub-directories and their contents. The -R option can be very dangerous; you may want to use it in conjunction with the -i option to confirm each deletion.
The rm command's
file operand can be a file or a directory name. If you are deleting a non-empty directory, you must use the -R (recursive) option.
You can learn more about the rm and rmdir commands and their options on their man pages. Type man rm or man rmdir and press
Type rm
file ... and press
file1 from the current directory (Figure 24 ).
Type rm followed by the wildcard search string and press
.bak from the current directory.
Type rm * and press
rm command. In the first, the
rm * command string deletes all files in the directory, but not the subdirectory named dir30. In the second, the
-Ri options delete all contents with confirmation; the only item still in the directory is the subdirectory named dir30.
You may want to include the -i option (for example, rm -i *) to confirm each deletion so you do not delete files by mistake.
Since the rm command cannot remove directories without the -R option, an error message may appear when you use the rm * command string in a directory that contains subdirectories (Figure 25 ).
Type rm -R * and press
Warning!
This is the most dangerous command in all of Unix. If you enter this command in the root directory (/), you will erase the entire disk (if you have permission). Use this command with care!
You may want to include the -i option (for example, rm -Ri *;
Figure 25 ) to confirm each deletion so you do not delete files or subdirectories by mistake.
Type rmdir
directory … and press
Originals in the current directory (Figure 26 ).
rmdir command, is not successful because the directory is not empty. The second, using the
rm -R command string, does the job.
The rmdir command will result in an error message if the directory you are trying to remove is not empty (Figure 26 ).
Type rm -R
directory and press
Originals even if it is not empty (Figure 26 ).