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
+43.3k Golang : Get hardware information such as disk, memory and CPU usage
+21k Golang : Sort and reverse sort a slice of strings
+5.3k Golang : fmt.Println prints out empty data from struct
+11.6k Golang : Secure file deletion with wipe example
+10.3k Golang : Convert file unix timestamp to UTC time example
+9k Golang : Handle sub domain with Gin
+5.4k How to check with curl if my website or the asset is gzipped ?
+35.1k Golang : Smarter Error Handling with strings.Contains()
+9.3k Golang : Play .WAV file from command line
+7.7k Golang : How to execute code at certain day, hour and minute?
+7.1k Golang : Use modern ciphers only in secure connection
+7.3k Golang : Scanf function weird error in Windows