Removing Existing Directories

Use the rmdir (remove directory) command to delete existing directories, for example:

rmdir acme reports/acme

rmdir will fail with an error message if any directory specified to be removed contains any files or subdirectories (except for dot [.] and dot-dot [..]):

$ rmdir acme
rmdir: acme: Directory not empty

If you get the error in the previous example and are sure you really want to delete that directory, use the rm command to delete all the files in that directory first. If there are any subdirectories, they must also be cleared and deleted before the main directory can be deleted.

For a fast (but potentially dangerous) way to remove a directory even if it still contains files or subdirectories, see the next section ...

Get Practical UNIX 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.