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 over 1 year
How to remove all the .pyc files recursively from a certain directory including sub-directories? I tried
$rm -f *.pyc
This seems to work for only the current directory, but not the directories following it. Please help me..
-
dogbane over 11 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 over 11 yearsI felt that this is a very simple command.. self explanatory..
-
Nehal J Wani over 11 yearsWhy doesn't anyone think of using
rm -rf *.pyc
? -
ypercubeᵀᴹ almost 9 years@NehalJ.Wani because that wouldn't work.
rm
does not have a search functionailty. therm -rf
can delete directories (and subdirectories recursively). But not search through subdirectories and delete only files.