rmdir

Used to delete empty directories

Supplementary instructions

rmdir command is used to delete empty directories. When a directory is no longer in use, or the disk space has reached the usage limit, you need to delete the directory that has lost its use value. Use the rmdir command to delete one or more empty subdirectories from a directory. This command deletes one or more subdirectories from a directory, where dirname represents the directory name. If the path is not specified in dirname, the directory specified by dirname in the current directory will be deleted; if dirname contains a path, the directory at the specified location will be deleted. When deleting a directory, you must have write permissions on its parent directory.

Note: Subdirectories should be empty before they are deleted. That is to say, all files in the directory must be deleted using the rm command. In addition, the current working directory must be above the deleted directory, not the deleted directory itself, nor a subdirectory of the deleted directory.

Although you can also use the rm command with the -r option to recursively delete all files in a directory and the directory itself, this is very dangerous.

grammar

rmdir(options)(parameters)

Options

-p or --parents: After deleting the specified directory, if the upper-level directory of the directory has become an empty directory, it will be deleted together;
--ignore-fail-on-non-empty: This option causes the rmdir command to ignore error messages caused by deleting non-empty directories;
-v or -verboes: Display the detailed execution process of the command;
--help: Display help information for the command;
--version: Display the version information of the command.

Parameters

Directory List: A list of empty directories to delete. When deleting multiple empty directories, use spaces to separate directory names.

Example

Delete the subdirectory named www in the working directory:

rmdir www

In the www directory under your working directory, delete the subdirectory named Test. If the www directory becomes an empty directory after Test is deleted, www will also be deleted.

rmdir -p www/Test

The following commands are equivalent to rmdir a/b/c, rmdir a/b, rmdir a

rmdir -p a/b/c