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
+31.8k Golang : How to convert(cast) string to IP address?
+16.4k Golang :Trim white spaces from a string
+18.3k Golang : Put UTF8 text on OpenCV video capture image frame
+10.5k Generate Random number with math/rand in Go
+17.5k Golang : Check if IP address is version 4 or 6
+8.3k Golang : Qt splash screen with delay example
+14k Golang : How to determine if a year is leap year?
+4.8k Golang : How to pass data between controllers with JSON Web Token
+16.4k Golang : How to extract links from web page ?
+5.3k JavaScript/JQuery : Redirect page examples
+62.8k Golang : Convert HTTP Response body to string