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
+7.6k Golang : Create zip/ePub file without compression(use Store algorithm)
+7.6k Golang : How to stop user from directly running an executable file?
+12.8k Android Studio : Highlight ImageButton when pressed on example
+7.1k Golang : Validate credit card example
+19.4k Golang : Get host name or domain name from IP address
+24k Golang : Fix type interface{} has no field or no methods and type assertions example
+18.8k Unmarshal/Load CSV record into struct in Go
+12.4k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+43.7k Golang : Get hardware information such as disk, memory and CPU usage
+7.5k Linux : How to fix Brother HL-1110 printing blank page problem
+4.8k Chrome : How to block socketloop.com links in Google SERP?
+7.2k Golang : A simple forex opportunities scanner