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.7k Golang : How to detect if a sentence ends with a punctuation?
+7.1k Golang : Fix go.exe is not compatible with the version of Windows you're running
+21.1k Get file path of temporary file in Go
+5.1k Golang : Convert source code to assembly language
+3.3k Golang *File points to a file or directory ?
+24k Golang : Get and Set User-Agent examples
+6.9k Golang : Random Rune generator
+3k Golang : Print instead of building pyramids
+16.4k Golang : Use regular expression to validate domain name
+12k Golang : File path independent of Operating System
+3.8k Golang : How to setup a disk space used monitoring service with Telegram bot