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
+2.9k Javascript : Empty an array example
+20.6k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+7.8k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+1k Golang : Switch Redis database redis.NewClient
+8.2k Golang : Characters limiter example
+10.2k Golang : Search and extract certain XML data example
+24.7k Golang : Change a file last modified date and time
+4k Unix/Linux/MacOSx : Get local IP address
+17.1k Golang : Clearing slice
+4.3k Unix/Linux : Get reboot history or check when was the last reboot date
+11.9k Golang : Get HTTP protocol version example
+8.6k Golang : Generate random elements without repetition or duplicate