Linux/MacOSX : Search and delete files by extension
Continuing from previous tutorial on how to search for files by extension with find
command. For this post, we will learn how to search for files that we want to delete.
To search current directory and directories under the current directory for files with .go , .py and .php extensions :
>find ~ -type f | grep -E "\.go$|\.py$|\.php$"
and to delete those files, simply add another pipe to rm
command :
>find ~ -type f | grep -E "\.go$|\.py$|\.php$" | | xargs -I {} rm {}
Hope this helps!
See also : Mac OSX : Find large files by size
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.5k Golang : What fmt.Println() can do and println() cannot do
+11.2k Golang : Arithmetic operation with numerical slices or arrays example
+6.7k Golang : Reverse a string with unicode
+16.4k Golang : How to log each HTTP request to your web server?
+27.8k Golang : Get first few and last few characters from string
+4.8k Golang : Error handling methods
+4k Fix Google Analytics Redundant Hostnames problem
+7.7k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+7.9k Golang : How to extract video or image files from html source code
+9.5k Golang : How to transmit update file to client by HTTP request example
+30.5k Golang : Copy directory - including sub-directories and files
+9k Android Studio : Simple input textbox and intercept key example