是否可以打印然后删除使用单个 'find' bash 命令找到的文件?

Is it possible to print and then remove files found with a single 'find' bash command?

我正在尝试使用单个 'find' 命令查找并打印所有以特定模式命名的文件。现在一切都很好。但是现在我试图在不编写第二个命令的情况下删除这些文件,所以我尝试使用参数“-delete”和“-exec rm -f {};”但是 none 他们实际上在终端中打印文件。

那么,是否真的可以打印这些文件,然后使用单个查找命令将其删除?

当然可以。使用 find-print 命令:

find ... -print -delete

-printfind 的隐式默认操作。当您显式指定 -delete-exec 之类的操作时,默认值将被覆盖,因此您必须再次显式指定它。来自 man find:

If no expression is given, the expression -print is used