Removing Files & Directories with rm & rmdirUnix includes two commands that you can use to delete files and directories: rm (remove) and rmdir (remove directory). Warning!
Tips
To remove a fileType rm file ... and press . For example, rm file1 removes the file named file1 from the current directory (Figure 24). To remove files using a wildcard characterType rm followed by the wildcard search string and press . For example, rm *.bak removes all files ending with .bak from the current directory. To remove all files in a directoryType rm * and press (Figure 25). Figure 25. Two more examples of the 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.Tips
To remove all files & subdirectories in a directoryType rm -R * and press (Figure 25). Warning!
Tip
To remove an empty directoryType rmdir directory … and press . For example, rmdir Originals removes the subdirectory named Originals in the current directory (Figure 26). Figure 26. This example shows two attempts to delete a subdirectory. The first, using the rmdir command, is not successful because the directory is not empty. The second, using the rm -R command string, does the job.Tip
To remove a directory & its contentsType rm -R directory and press . For example, rm -R Originals removes the directory named Originals even if it is not empty (Figure 26). |