在Linux中如何强制删除目录?
时间:2019-11-20 08:53:35 来源:igfitidea点击:
Linux 无法删除目录 rmdir: failed to remove dir1: Directory not empty
在Linux中如何强制删除目录?
rmdir命令只能删除空目录,
如果是非空目录,需要使用rm命令删除
如何删除包含子目录和文件的目录
语法为:
rm -rf dirName
删除目录
rm -rf /home/theitroad/temp/
如何在Linux中删除目录?
将-v选项传递给rm命令,会显示删除过程,如下所示:
rm -rfv dirname
其中:
- -r:递归删除
- -f:强制删除目录
- -v:详细输出
如何删除减号开头的目录
要删除名称以-开头的文件夹(例如-backups),请使用以下命令之一:
rm -rfv -- -backups/
或者
rm -rfv ./-bacups/
查看rm命令帮助
执行:
rm --help
输出示例:
-f, --force ignore nonexistent files and arguments, never prompt -i prompt before every removal -I prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes --interactive[=WHEN] prompt according to WHEN: never, once (-I), or always (-i); without WHEN, prompt always --one-file-system when removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument --no-preserve-root do not treat '/' specially --preserve-root[=all] do not remove '/' (default); with 'all', reject any command line argument on a separate device from its parent -r, -R, --recursive remove directories and their contents recursively -d, --dir remove empty directories -v, --verbose explain what is being done --help display this help and exit --version output version information and exit