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
+18k Golang : Get command line arguments
+13.7k Golang : Get current time
+7.6k Golang : Getting Echo framework StartAutoTLS to work
+12.9k Golang : Convert(cast) int to int64
+9.3k Golang : Changing a RGBA image number of channels with OpenCV
+16.2k CodeIgniter/PHP : Create directory if does not exist example
+17.2k Golang : Check if IP address is version 4 or 6
+12.1k Golang : Display list of countries and ISO codes
+6.9k Golang : A simple forex opportunities scanner
+13.6k Golang : Get dimension(width and height) of image file
+11k Golang : Fix - does not implement sort.Interface (missing Len method)
+12.8k Golang : Calculate elapsed years or months since a date