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
+7.1k Golang : Check if one string(rune) is permutation of another string(rune)
+20k Golang : Determine if directory is empty with os.File.Readdir() function
+8k Android Studio : Rating bar example
+33.8k Golang : Proper way to set function argument default value
+11.5k Golang : Surveillance with web camera and OpenCV
+9.2k Golang : Generate EAN barcode
+12.9k Swift : Convert (cast) Int to String ?
+6.7k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+8k Golang : Routes multiplexer routing example with regular expression control
+13.3k Golang : Read XML elements data with xml.CharData example
+12k Golang : Get remaining text such as id or filename after last segment in URL path
+14.4k Golang : GUI with Qt and OpenCV to capture image from camera