当我这样做
rm file.txt
或
rm *.txt
每个文件都会提示我,因为我没有为 rm
指定 -f
选项。
但是当我这样做的时候:
find . -type f -name '*.txt' | xargs rm
文件在未经确认的情况下被删除。
这背后的逻辑是什么?是否可以在某些文档中找到原因?我无法解释为什么会这样。
最佳答案
您将 rm 命令的别名设置为“rm -i”。因此,如果您像在
中那样直接调用命令rm file.txt
或
rm *.txt
别名将被扩展。如果你像在
中那样用xargs调用它find . -type f -name '*.txt' | xargs rm
rm 作为简单的字符串参数传递给 xargs,稍后由 xargs 调用,无需 shell 的别名替换。 你的别名可能在 ~/.bashrc 中定义,以防你想删除它。
关于linux - 使用 find 和 xargs 使用 rm 删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42828021/