Previous | Table of Contents | Next |
DESCRIPTION
The external rmdir command removes a directory. The directory must be empty. An empty directory only has two entries, the . (dot) representing itself and the .. (dot dot) representing its parent directory.
The rmdir command is a safer way to perform directory removal than using the rm -r command. It checks the directory for the existence of files and subdirectories. If any exist, rmdir complains and exits without removing the directory.
NOTE:
It is invalid to remove your current . (dot) directory or your parent .. (dot dot) directory.
COMMAND FORMAT
Following is the general format of the rmdir command.
rmdir [ -ps ] directory_list rm -r directory_list
Options
The following options may be used to control how rmdir functions.
-p | Removes empty directories specified in the directory path . If you specify a directory by a pathname and its parent directories are empty, they also are removed. The name of each directory is displayed on the standard output as it is removed. Directories that are not removed are displayed on the standard error. |
-s | Suppress any messages produced. Both standard error and standard output are suppressed. |
|
---|
BSD (Berkeley) |
Berkeley does not support any options on the rmdir command. |
|
Arguments
The following argument may be passed to the rmdir command.
directory_list | One or more directories you wish to remove. The directories must be empty. The directory names used can be single filenames or pathnames. |
DIAGNOSTICS AND BUGS
The following messages may be returned by rmdir .
nonempty directory: | The directory contains files. Remove the files by typing rm directory_name/* or use the rm -r directory_name command. |
current directory illegal | You cannot remove your current or parent directory. cd to a different directory and then remove the directory. You must be in a directory at least one level above the one you wish to remove. |
RELATED COMMANDS
Refer to the mkdir , rm , ksh , and umask commands described in modules 89, 114, 71, and 147 respectively.
APPLICATIONS
The rmdir command is useful for removing a directory. It is the restrictive or safe way to remove a directory. It will complain if any files exist in the directory and fail. You have to remove all files in the directory before rmdir will remove the directory. The rm -r command is a much more powerful command, but with power comes the hazards of carelessness. UNIX has no mercy when it comes to deleted files. Therefore, be extremely careful if you venture to use the rm -r command.
TYPICAL OPERATION
In this activity you use the rmdir command to remove a directory you created by mistake. Begin at the shell prompt.
Previous | Table of Contents | Next |