Find and remove specific files via the command line.
Nov 24, 2020
For example, on a Mac, you’ll often find .DS_Store
files. To find and remove these you can run the following command to search for and remove every instance:
$ find . -type f -name ".DS_Store" -exec rm {} ;
This will find all files (-type f
) called .DS_Store
and execute the rm
(remove) command on that set {}
.
Run from the top directory and it will recurse its way into all sub directories and remove the files. This can be a dangerous command so use with caution.
You can also adapt the command to execute something else (e.g. a mv
to another location for example.