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
+13.8k Golang : Simple word wrap or line breaking example
+16.9k Golang : How to tell if a file is compressed either gzip or zip ?
+11.5k Golang : Verify Linux user password again before executing a program example
+6.1k CodeIgniter : form input set_value cause " to become & quot
+18.4k Golang : convert int to string
+5.7k Golang : Denco multiplexer example
+10.3k Golang : Get local time and equivalent time in different time zone
+27.8k Golang : Connect to database (MySQL/MariaDB) server
+5.6k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+11.4k Golang : Surveillance with web camera and OpenCV
+13.7k Golang : concatenate(combine) strings
+7k Golang : Check if one string(rune) is permutation of another string(rune)