I wanted to delete some Python .pyc files. First, I looked for them. (I always want to see what I'm wiping out before I do it.) So--
find . -name *.pyc
It returned about a dozen pyc files. Now to delete.
find has a
-delete option to delete whatever it finds. So I quickly threw that into the previous command:
# DON'T DO THIS
find . -delete -name *.pyc
Then I went to continue my work. But everything was gone. I had deleted the entire tree!
I was supposed to put
# the right way to delete what it finds
find . -name *.pyc -delete
This was a painful reminder that
find simply executes the expressions passed to it in left-to-right order while applying any given operators, like and/or/not. (See
When I had the
-delete right after the path, I was basically telling
find to traverse the tree, delete each item as it encounters them, then match it with the given name (which it doesn't do because it was deleted).