This command lists all the files match the provided name:

find . -iname .DS_Store

But when I use -delete parameter with it, I can't see the list of deleted files. They just get deleted.

Preferably without making it complicated with | xarg .. or -exec rm {}, is there any magic flag to see the deleted files when using find . -iname .DS_Store -delete?

PS: I know I can run the command without delete flag before, but I'm looking for something like print0 (though prints uglily) to get the job done.


1 Answer 1


Just add -print to the end of the command:

find . -name .DS_Store -delete -print

This would output the pathnames of the files found.

If this is on a macOS system (or on any of the BSD systems), using the default implementation of find there, then the -delete predicate always returns true, meaning that the -print would also always come into effect. This means that the command above would print all found pathnames, regardless of whether they were successfully deleted or not. The -delete predicate in GNU find would return false if the name could not be deleted.

If you're on a macOS or BSD system, and if this matters to you, then use

find . ! -type d -name .DS_Store -exec rm {} \; -print

instead. Here, the rm would return a non-zero exit status if it failed to remove the given name, and this in turn means that the -print would not come into effect for that pathname. I've also added ! -type d since rm only deletes non-directories (when not using rm -r).


Not the answer you're looking for? Browse other questions tagged .