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
+11.6k Golang : Concurrency and goroutine example
+15.5k Golang : Validate hostname
+18.5k Golang : Iterating Elements Over A List
+14.2k Golang : How to shuffle elements in array or slice?
+18.8k Golang : Read input from console line
+13.9k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+16.3k Golang : Send email and SMTP configuration example
+11.1k Golang : Calculate Relative Strength Index(RSI) example
+47.6k Golang : Convert int to byte array([]byte)
+9.9k Golang : Get escape characters \u form from unicode characters
+8.7k Golang : Executing and evaluating nested loop in html template