“更正确”的解决方案如下:
xargs -I{} rm -r {} < files
Run Code Online (Sandbox Code Playgroud)
这调用rm -r
, 其中{}
被替换为文件名。
为什么?通过管道将文件与空格连接xargs
将导致错误的参数。假设您的文件列表如下所示:
/path/to/file 1
/path/to/file_2
Run Code Online (Sandbox Code Playgroud)
然后xargs rm -r < list.txt
会尝试删除/path/to/file
,1
和/path/to/file_2
。绝对不是你想要的。在通过管道传输 UNIX/Linux 命令时,请始终注意路径中的空格。
归档时间: |
|
查看次数: |
5927 次 |
最近记录: |