Bash find 命令详细输出

Ale*_*lex 51 linux bash find

有没有办法告诉 bashfind命令输出它在做什么(详细模式)?

例如对于命令: find /media/1Tb/videos -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \;输出:

Found /media/1Tb/videos/102, executing rm -rf /media/1Tb/videos/102
...
Run Code Online (Sandbox Code Playgroud)

Ign*_*ams 73

你可以用 来编造一些东西-printf,但最简单的就是-print在最后加上。这将显示成功删除的内容。

  • 对我来说,使用“-exec rm -vf {} \;” 工作得更好。 (8认同)
  • 好的!也适用于 -delete:`find -L。-type l -delete -print` (3认同)

Ham*_*sLi 20

rm -vf用于详细 rm 输出如何。

$ touch file1 file2 file3
$ find . -name "file?" -exec rm -vf {} \;
removed `./file2'
removed `./file3'
removed `./file1'
Run Code Online (Sandbox Code Playgroud)


hlo*_*dal 7

另一种方法是让命令执行sh -x

$ find . -type f -print0 | xargs -0 -n1 echo rm | sh -x
+ rm ./file1
+ rm ./file2
+ rm ./file3
Run Code Online (Sandbox Code Playgroud)