“更正确”的解决方案如下:
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 命令时,请始终注意路径中的空格。