Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用xargs删除目录_Linux_Command Line Interface_Xargs - Fatal编程技术网

Linux 使用xargs删除目录

Linux 使用xargs删除目录,linux,command-line-interface,xargs,Linux,Command Line Interface,Xargs,我有一个文件夹列表,我想用find生成的xargs删除这些文件夹 查找命令 test.txt 命令和详细输出 但是目录没有被删除 我正在使用-0,因为当我真正运行它时可能会有空白,我正在生成列表,这样我就可以确认在文本文件中删除每一行是安全的,而不是直接通过管道查找到xargs 有什么建议吗?那么,让我首先说我非常不喜欢xargs。如果你不小心,那真的很危险。也就是说,类似这样的方法是可行的: find/home/users/luke-mindepth 1-maxdepth 1-type d |

我有一个文件夹列表,我想用find生成的xargs删除这些文件夹

查找命令 test.txt 命令和详细输出 但是目录没有被删除

我正在使用-0,因为当我真正运行它时可能会有空白,我正在生成列表,这样我就可以确认在文本文件中删除每一行是安全的,而不是直接通过管道查找到xargs


有什么建议吗?

那么,让我首先说我非常不喜欢xargs。如果你不小心,那真的很危险。也就是说,类似这样的方法是可行的:

find/home/users/luke-mindepth 1-maxdepth 1-type d | xargs-verbose-I{}rm-vfr{}

通过将{}括在双引号中,可以消除任何涉及空格的问题。我倾向于尽可能多地使用或使用类似的东西。我把mindepth放在那里是为了确保它不包含父文件夹,因为一些操作系统的maxdepth包含父目录ie'.'将有效地破坏整个文件夹。我想你不会想要的

同样,对xargs要非常小心。这种命令可能是邪恶的。我会说先在它上面添加-0,让它显示将要运行的内容,然后在确定之后删除-0


希望能有所帮助。

我提到我不能直接从find使用管道,因为需要检查每个目录以进行删除-使用text.txt文件作为输入是否有效?作为审查的一部分,我删除了。列表中的当前目录确认您可以使用text.txt作为输入
$ find /home/users/lukes -maxdepth 1 -type d > test.txt
/home/users/lukes/2
/home/users/lukes/6
/home/users/lukes/7
/home/users/lukes/3
/home/users/lukes/1
/home/users/lukes/4
/home/users/lukes/5
$ xargs --verbose -0 -I{} rm -rfv {} < test.txt 
rm -rfv /home/users/lukes/2
/home/users/lukes/6
/home/users/lukes/7
/home/users/lukes/jadu_package_1.1.0
/home/users/lukes/3
/home/users/lukes/1
/home/users/lukes/4
/home/users/lukes/5