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
+19k Golang : Delete duplicate items from a slice/array
+6.9k Golang : Check if password length meet the requirement
+8.1k Golang : Grayscale Image
+7.1k Golang : Calculate BMI and risk category
+25.5k Golang : Get current file path of a file or executable
+9.9k Golang : List available AWS regions
+5.9k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+15.1k Golang : How to check for empty array string or string?
+12.5k Golang : How to display image file or expose CSS, JS files from localhost?
+5.5k Golang : How to deal with configuration data?
+5.4k JavaScript/JQuery : Redirect page examples
+14.8k Golang : Convert(cast) int to float example