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
+33.9k Golang : Get file last modified date and time
+8.3k Mac OSX : Get a process/daemon status information
+35.1k Golang : Convert date or time stamp from string to time.Time type
+6.7k Golang : Test if an input is an Armstrong number example
+9k Golang : Get escape characters \u form from unicode characters
+20.6k Golang : Match strings by wildcard patterns with filepath.Match() function
+9.9k Golang : Calculate Relative Strength Index(RSI) example
+8.4k Facebook : Getting the friends list with PHP return JSON format
+3.8k Facebook : How to place save to Facebook button on your website
+11k Golang : 2 dimensional array example
+9.6k Golang : Bubble sort example
+39.7k Golang : How to check if a string contains another sub-string?