`rm -f` 当别名为 `rm -i` 时要求确认

`rm -f` asks for confirmation, when aliased as `rm -i`

我正在使用此命令尝试删除一个非常大的文件夹中的所有 Thumbs.db 文件。我认为 -f 应该在不要求确认的情况下强制删除,但我仍然被提示在每个文件上输入 "y" 或 "n"。

find "megapacks" -name Thumbs.db -ok rm -f {} \;

我尝试 type rm 看看是否有别名,它的响应是

rm is aliased to `rm -i'

我尝试使用 /bin/rm,但系统仍然提示我

find "megapacks" -name Thumbs.db -ok /bin/rm -f {} \;

还有人知道如何避免确认吗?

但是我觉得问题是你把-ok传给了find,也就是

Like -exec but ask the user first.

如果别名是问题所在,只需取消设置别名即可:

unalias rm

请注意,这只会影响当前 shell 会话。

您还可以为 find 使用 -delete 选项:

find "megapacks" -name Thumbs.db -delete

问题出在 -ok 选项,根据 man find:

Like -exec but ask the user first. If the user agrees, run the command. Otherwise just return false.

这应该适用于 -exec:

find "megapacks" -name Thumbs.db -exec /bin/rm -f {} \;

或更快:

find "megapacks" -name Thumbs.db -exec /bin/rm -f {} +