Linux command
rmdir 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Remove an empty directory
rmdir [path/to/directory]
Remove multiple empty directories
rmdir [dir1] [dir2] [dir3]
Remove directory and empty parents
rmdir -p [path/to/directory]
Remove with verbose output
rmdir -v [path/to/directory]
Ignore errors
rmdir --ignore-fail-on-non-empty [path/to/directory]
Remove nested empty directories
rmdir -p [parent/child/grandchild]
说明
rmdir removes empty directories. Unlike rm -r, it will not remove directories that contain files or subdirectories, providing a safety check against accidental data loss. With the -p option, rmdir removes the specified directory and then attempts to remove each parent directory in the path, stopping when a non-empty directory is encountered or removal fails. rmdir is useful in scripts where you want to clean up empty directories without risking removal of directories with content.
参数
- -p, --parents
- Remove directory and its empty ancestor directories.
- -v, --verbose
- Print a message for each removed directory.
- --ignore-fail-on-non-empty
- Ignore failures caused solely by non-empty directories.
- --help
- Display help message.
- --version
- Display version information.
FAQ
What is the rmdir command used for?
rmdir removes empty directories. Unlike rm -r, it will not remove directories that contain files or subdirectories, providing a safety check against accidental data loss. With the -p option, rmdir removes the specified directory and then attempts to remove each parent directory in the path, stopping when a non-empty directory is encountered or removal fails. rmdir is useful in scripts where you want to clean up empty directories without risking removal of directories with content.
How do I run a basic rmdir example?
Run `rmdir [path/to/directory]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -p, --parents do in rmdir?
Remove directory and its empty ancestor directories.