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.9k Python : Find out the variable type and determine the type with simple test
+6.9k Mac OSX : Find large files by size
+18.9k Golang : Padding data for encryption and un-padding data for decryption
+21.2k Golang : Clean up null characters from input data
+15.6k Golang : Force download file example
+9.7k Golang : List available AWS regions
+18.8k Golang : Delete duplicate items from a slice/array
+5.8k Golang : Find change in a combination of coins example
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+7.8k Golang : Load DSA public key from file example
+41.4k Golang : Convert string to array/slice
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example