findverbose

How to show deleted file when using command `find . -name sample.txt -delete`


I need the output just like rm -v sample.txt. Are there options like "-v" in command find?


Solution

  • Tested with FreeBSD and Busybox implementations of find:

    $ find . -name sample.txt  -delete -exec echo removed "'{}'" \; | sed "s,^removed '\./,removed ',"
    removed 'sample.txt'
    

    With GNU find you can also use -printf:

    $ find . -name sample.txt -printf "removed '%f'\n" -delete
    removed 'sample.txt'