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
+21.1k Golang : GORM create record or insert new record into database example
+17.1k Golang : Defer function inside init()
+8.2k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+5.4k Swift : Get substring with rangeOfString() function example
+6.9k Golang : Dealing with postal or zip code example
+9.1k Golang : Accessing content anonymously with Tor
+9.3k Golang : interface - when and where to use examples
+14.3k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+4.5k Which content-type(MIME type) to use for JSON data
+54.5k Golang : Unmarshal JSON from http response
+50.9k Golang : Check if item is in slice/array