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
+4.6k Golang : Compare files modify date example
+12.4k Golang : How to read JPG(JPEG), GIF and PNG files ?
+15.5k Golang : Get file last modified date and time
+3.2k Golang : Generate human readable password
+10.3k Golang : Send email with attachment
+4.5k Golang : Accept any number of function arguments with three dots(...)
+9.4k nginx: [emerg] unknown directive "ssl"
+18.4k Golang : Strings to lowercase and uppercase example
+12.1k Golang : Archive directory with tar and gzip
+3.3k Golang : Get final balance from bit coin address example
+8.8k Golang : Get number of CPU cores