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
+7.2k Golang : Rot13 and Rot5 algorithms example
+19.5k Golang : Count JSON objects and convert to slice/array
+5.5k Unix/Linux : Get reboot history or check when was the last reboot date
+6.2k Golang : Calculate diameter, circumference, area, sphere surface and volume
+5.4k Javascript : How to refresh page with JQuery ?
+16.7k Golang : How to save log messages to file?
+5.9k Linux/Unix : Commands that you need to be careful about
+7.3k Javascript : Push notifications to browser with Push.js
+14.6k Golang : Search folders for file recursively with wildcard support
+5.7k Fontello : How to load and use fonts?
+20.8k Golang : Create and resolve(read) symbolic links