Remove files recursively in Linux
11,511
Solution 1
You can use
cd <your_directory>
find . -name "*.pyc" -exec rm -rf {} \;
This will remove all the *.pyc files from your current directory and its sub directory
Solution 2
Use find:
find /some/directory -type f - name "*.pyc" -exec rm -f {} \;
or, if your find has the -delete option:
find /some/directory -type f - name "*.pyc" -delete
Solution 3
find /var/www/html -name "*.pyc" -delete
Related videos on Youtube
Author by
Admin
Updated on September 18, 2022Comments
-
Admin about 1 monthHow to remove all the .pyc files recursively from a certain directory including sub-directories? I tried
$rm -f *.pycThis seems to work for only the current directory, but not the directories following it. Please help me..
-
dogbane almost 10 yearsYou need to quote *.pyc otherwise the shell will expand it. This will not work if there are pyc files in the base directory.
-
Admin almost 10 yearsI felt that this is a very simple command.. self explanatory.. -
Nehal J Wani almost 10 yearsWhy doesn't anyone think of usingrm -rf *.pyc? -
ypercubeᵀᴹ over 7 years@NehalJ.Wani because that wouldn't work.rmdoes not have a search functionailty. therm -rfcan delete directories (and subdirectories recursively). But not search through subdirectories and delete only files.