3.22. Deleting a File: rmThe rm utility allows you to remove a file's label from the hierarchy. When no more labels reference a file, Linux removes the file itself. In most cases, every file only has one label, so the act of removing the label causes the file's physical contents to be deallocated. However, in Chapter 4, "GNU Utilities for Power Users," I'll show you some occasions where a single file has more than one label. In these cases, a label may be removed without affecting the file that it refers to. Figure 3-25 describes rm.
To remove every file in the "lyrics.draft" directory, I moved into the "lyrics.draft" directory and used rm: $ cd lyrics.draft ...move to "lyrics.draft" dir. $ rm heart.ver1 heart.ver2 heart.ver3 heart.ver4 heart.ver5 $ ls ...nothing remains. $ _ Now that all the files were erased, I moved back to my home directory and erased the draft directory: $ cd ...move to my home directory. $ rmdir lyrics.draft ...this time it works. $ _ As you'll see in Chapter 5, "The Linux Shells," there's a much easier way to erase a collection of files when you're using a shell. I could have written the following instead: $ cd lyrics.draft ...move into "lyrics.draft" directory. $ rm * ...erase all files in current dir. Even better, I could have used the more advanced -r option of rm to delete the "lyrics.draft" directory and all of its contents with just one command: $ cd ...move to my home directory. $ rm -r lyrics.draft ...recursively delete directory. $ _ |