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 : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+9.2k Android Studio : Checkbox for user to select options example
+4.2k Golang : Constant and variable names in native language
+4.5k Golang : Generate Interleaved 2 inch by 5 inch barcode
+24.7k Golang : missing Mercurial command
+6.2k Nginx : How to block user agent ?
+14.2k Golang : Validate hostname
+9.2k Golang : Resolve domain name to IP4 and IP6 addresses.
+17.2k Golang : How to get hour, minute, second from time?
+5.3k Golang & Javascript : How to save cropped image to file on server
+12.9k Golang : Simple word wrap or line breaking example
+48.9k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate