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
+6.7k Golang : Warp text string by number of characters or runes example
+9.4k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+16.1k Golang : Read large file with bufio.Scanner cause token too long error
+16.5k Golang : Test floating point numbers not-a-number and infinite example
+11.3k CodeIgniter : How to check if a session exist in PHP?
+8k Javascript : Put image into Chrome browser's console
+9.1k Golang : How to use Gorilla webtoolkit context package properly
+5.6k PHP : Fix Call to undefined function curl_init() error
+16k Golang : Get digits from integer before and after given position example
+4.8k JavaScript: Add marker function on Google Map
+9.9k Golang : interface - when and where to use examples
+7.2k Golang : Gorrila mux.Vars() function example