Reputation: 87
I am deleting the files in all the directories and subdirectories using the command below:
find . -type f -name "*.txt" -exec rm -f {} \;
But I want to know which are the files deleted along with their paths. How can I do this?
Upvotes: 1
Views: 584
Reputation: 42094
Simply add a -print
argument to your find
.
$ find . -type f -name "*.txt" -print -exec rm -f {} \;
As noted by @JonathanRoss below, you can achieve an equivalent result with the -v
option to rm
.
It's not the scope of your question, but more generally it gets more interesting if you want to delete directories recursively. Then:
-exec rm -r
argument keeps it silent-print -exec rm -r
argument reports the toplevel directories you're operating on-exec rm -rv
argument reports all you're removingUpvotes: 3