Print Files Acted on by Find Command

find

I use the following command in order to delete only the files that start with DBG and older then two day , but this syntax not print the files that deleted

find /tmp  -type f -mtime +2 -name "DBG*" -exec rm {} \;

How to add to this the find syntax , the print in order to print the deleted files?

Best Answer

Just use -print flag:

find /tmp  -type f -mtime +2 -name "DBG*" -exec rm {} \; -print

or, if rm supports the -v option, let rm do it all:

find /tmp  -type f -mtime +2 -name "DBG*" -exec rm -v {} +

or if your find supports -delete:

find /tmp  -type f -mtime +2 -name "DBG*" -delete -print

(note that the first two have a race condition that could allow one to delete DBG* files anywhere on the file system)

Related Question