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
+8k Golang : Go as a script or running go with shebang/hashbang style
+9k Golang : Use regular expression to get all upper case or lower case characters example
+9.5k Swift : Convert (cast) String to Integer
+7.8k Yum Error: no such table: packages
+13.5k Golang : Find commonalities in two slices or arrays example
+25.1k Golang : Calculate future date with time.Add() function
+6.7k Golang : Grayscale Image
+17k Golang : Iterating Elements Over A List
+7.7k Golang : Find network service name from given port and protocol
+15.3k Golang : Send email and SMTP configuration example
+9.3k JavaScript/JQuery : Detect or intercept enter key pressed example
+37.9k Golang : How to iterate over a []string(array)