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
+31.2k Golang : Regular Expression for alphanumeric and underscore
+6.5k Golang : Convert source code to assembly language
+17.8k Golang : Get RGBA values of each image pixel
+5.6k Golang : Calculate pivot points for a cross
+24.2k Golang : How to read integer value from standard input ?
+17.9k Golang : Get current URL example
+15.1k Golang : Test floating point numbers not-a-number and infinite example
+6.2k Golang : Example of custom handler for Gorilla's Path usage.
+9.2k Android Studio : Checkbox for user to select options example
+18.3k Golang : Determine if directory is empty with os.File.Readdir() function
+8.1k Golang : Generate Codabar
+33.5k Golang : Upload and download file to/from AWS S3