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
+10.9k Use systeminfo to find out installed Windows Hotfix(s) or updates
+44k Golang : Use wildcard patterns with filepath.Glob() example
+7k Golang : Dealing with struct's private part
+13.3k Golang : How to determine if a year is leap year?
+5k Golang *File points to a file or directory ?
+9.2k Golang : ffmpeg with os/exec.Command() returns non-zero status
+9.1k Golang : Read file with ioutil
+8.9k Golang : Play .WAV file from command line
+4.4k Unix/Linux : How to pipe/save output of a command to file?
+5.8k Golang : Calculate US Dollar Index (DXY)
+7.5k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+19.1k Golang : Close channel after ticker stopped example