Files – Find Files Matching Template and Remove

filenamesfilesfind

I have a large amount of folders and files.
I need to parse it and find only those with the extension xmp to finally remove them.

How can I achieve this and keep track of the name of the removed files?

To find: I know I can use find /path -name "*.xmp"
But how can I run two commands on the output? keep file path and name in removelist.txt and remove it.

Best Answer

With GNU find's -fprint and -delete actions:

find . -name "*.xmp" -fprint "removelist.txt" -delete
  • -fprint file - print the full file name into file file. If file does not exist when find is run, it is created; if it does exist, it is truncated.
  • -delete - delete files
Related Question