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
+9k Golang : Get escape characters \u form from unicode characters
+12.9k Golang : concatenate(combine) strings
+12k Golang : Linear algebra and matrix calculation example
+10.6k Golang : How to detect a server/machine network interface capabilities?
+18.5k Golang : Append content to a file
+4.2k JavaScript/JQuery : Redirect page examples
+16k Golang : How to save log messages to file?
+6k Golang : Mapping Iban to Dunging alphabets
+5.7k Golang : Find the shortest line of text example
+22.3k Golang : Check if element exist in map
+8.6k Golang : Turn string or text file into slice example