Removing Directories with rmdir

Another handy thing you can do is to remove directories using rmdir. Think of removing directories as trimming branches on a tree. That is, you can’t be sitting on the branch you want to trim off. You have to sit on the next closest branch; otherwise, you’ll fall to the ground along with the branch you trim off. Ouch! Similarly, when you remove a directory, you must not be located in the directory you want to remove.

You must remove a directory’s contents (all subdirectories and files) before you remove the directory itself. In doing so, you can verify what you’re removing and avoid accidentally removing important stuff. In the following steps (illustrated in Code Listing 2.10), we’ll show you how to remove a ...

Get Unix Third Edition: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.