Ever try to delete files with unix shell find? Use the -delete option
Here's how to do it with the -delete
option!
Use the find command option -delete
:
find . -name '*.pyc' -delete
Of course, do try a dry run without the -delete
, to see if you are going to delete what you want!!! Those computers do run so darn fast! ;-)
+1 for taking the initiative and finding the solution to your issue yourself. A couple of rather minor notes:
I would recommend getting into the habit of using the -type f
flag when you're wanting to delete files. This restricts find
to files that are actually files (i.e. not directories or links). Otherwise you might inadvertently delete a directory, which is probably not what you wanted to do. (That said, unless you have a directory named 'something.pyc', that wouldn't be an issue for your example command. It's just a good habit in general.)
Also, just to let you know, if you decide use the -exec rm..
version, it would run faster if you did this instead:
find . -type f -name '*.pyc' -exec rm {} \+
This version adds as many arguments to a single invokation of rm
as it can, thereby reducing the total number of calls to rm
. It works pretty much like the default behavior in xargs
.