We often need command to recursively delete files from the current and sub-directories. Most of us execute the following command to do so.

rm -rf *.pyc

But to our utter surprise we find that it does not delete files from sub-directories. Well “r” option works only when you want to delete the directory.
Use the following command to delete the files successfully. Just change the file type based on the requirement.

find . -name \*.pyc -delete

If you are working on python project and want to delete the “pyc” files, to make sure that python picks your new changes, then you should use “pyclean” which gets installed with “python-minimal” package. Execute the command given below to make sure that you have “pyclean”

which pyclean
/usr/bin/pyclean

If you get some output, this implies that pyclean is installed in your system and you can use it to delete the *.pyc and *.pyo files. If it is not installed, then you can fallback to the above delete command which works for any kind of file types.

If you think that you know better command to do the same job, then please share it in the comment section.

,
Trackback

no comment untill now

Add your comment now