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
+3.2k JavaScript : Rounding number to decimal formats to display currency
+9.1k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+5.1k Golang : Lock executable to a specific machine with unique hash of the machine
+10.9k Golang : Date and Time formatting
+6.2k Golang : Routes multiplexer routing example with regular expression control
+4.3k Golang : Map within a map example
+21.6k Golang : dial tcp: too many colons in address
+13.3k Golang : File path independent of Operating System
+2.9k Javascript : Access JSON data example
+15k Golang : Fix cannot download, $GOPATH not set error
+7.9k Golang : Get UDP client IP address and differentiate clients by port number
+4.2k Golang : List all packages and search for certain package