rmdir

rmdir removes directories — but only empty ones. If a directory still has anything in it, rmdir leaves it alone and reports the failure.

rmdir [options] directory...
$ rmdir old-cache/

That refusal to touch a non-empty directory is the whole point of rmdir: it is the safe way to remove a directory you believe is empty. If it is not empty, you find out instead of losing the contents. To remove a directory together with everything inside it, use rm -r.

Options #

OptionEffect
-p, --parentsRemove the directory and then its ancestors, as long as each becomes empty in turn. rmdir -p a/b/c removes a/b/c, then a/b, then a.
--ignore-fail-on-non-emptyDo not treat "directory not empty" as a failure. Other failures are still reported. Useful when clearing out whatever directories happen to be empty and leaving the rest.
-v, --verbosePrint a line for each directory as it is removed.

Exit status #

CodeMeaning
0Every directory was removed.
1A directory could not be removed — it was not empty, did not exist, or removal was refused.

Edit this page