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 Linux : sudo yum updates not working
+23.4k Golang : Create PDF file from HTML file
+6k Golang : Null and nil value
+16.8k Golang : Check if a directory exist or not
+18.9k Nginx + FastCGI + Go Setup.
+8.9k Golang : Use regular expression to get all upper case or lower case characters example
+32.4k Golang : Call a function after some delay(time.Sleep and Tick)
+27.8k Golang : Save map/struct to JSON or XML file
+4.6k Python : Print unicode escape characters and string
+6.4k Golang : Handling Yes No Quit query input
+7.9k Golang : Generate random Chinese, Japanese, Korean and other runes
+9.5k Golang : Fix go.exe is not compatible with the version of Windows you're running