rmdir(1) — Commands
NAME
rmdir − Removes a directory
SYNOPSIS
rmdir directory ...
FLAGS
-pRemoves all directories in a pathname. For each directory argument, the directory entry it names is removed.
If the directory argument includes more than one pathname component, effects equivalent to the following command occur:
rmdir -p $(dirname directory)
That is, rmdir recursively removes each directory in the pathname.
DESCRIPTION
The rmdir command removes a directory from the system. The directory must be empty before you can remove it, and you must have write permission in its parent directory. Use the ls -al command to see if a directory is empty.
If a directory and a subdirectory of that directory are specified in a single invocation of rmdir, the subdirectory must be specified before the parent directory so that the parent directory will be empty when rmdir tries to remove it.
EXAMPLES
1.To empty and remove a directory, enter:
rm mydir/∗ mydir/.∗
rmdir mydir
This removes the contents of mydir, then removes the empty directory. The rm command displays an error message about trying to remove the directories . (dot) and .. (dot dot), and then rmdir removes them.
Note that rm mydir/∗ mydir/.∗ first removes files with names that do not begin with a . (dot), then those with names that do begin with a . (dot). You may not realize that the directory contains filenames that begin with a . (dot) because the ls command does not normally list them unless you use the -a flag to see the files whose names begin with a . (dot).
2.To remove all of the directories in the pathname a/b/c, enter:
rmdir -p a/b/c
Use a command like this one if directory a in the current directory is empty except that it contains a directory b and a/b is empty except that it contains a directory c.