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
+7.9k Golang : Sort and reverse sort a slice of floats
+7.3k Golang : Qt Yes No and Quit message box example
+6.7k Golang : On lambda, anonymous, inline functions and function literals
+8.5k Golang : Generate random integer or float number
+4.8k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+9.5k Golang : Print UTF-8 fonts on image example
+8.9k Golang : Create S3 bucket with official aws-sdk-go package
+7.3k Golang : Populate or initialize struct with values example
+17.1k Golang : Convert PNG transparent background image to JPG or JPEG image
+5.8k Golang : Shuffle strings array
+7k Golang : Scramble and unscramble text message by randomly replacing words
+7.5k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral