How do i delete a group of files ending with specific characters?
Assuming there are many files that meet the specifications and may be in more then one location, I'd use the find
command from Terminal, as shown in the following simple example:
$ find . -type f \( -iname '*_n.png' -o -iname '*_s.png' \)
./Pictures/foobar_n.png
./Pictures/Temp/barfoo_s.png
$
In the output of the find
command above, we see it found the two sample files I created for testing. As I'm sure those are the files I want to delete I run the same command but with adding -delete
to it, as shown below:
find . -type f \( -iname '*_n.png' -o -iname '*_s.png' \) -delete
If all the files are in the same directory or you just want to delete these files in a specific directory, use:
cd /path/to/directory
rm *_[ns].png
NOTE: Using find
with the -delete
option or rm
immediately deletes the files found, they are not placed in the Trash and they are generally not recoverable!
So do not use this commands unless you're okay with the note above!
If you prefer to use a GUI method, there is a nice freeware app by DEVONtechnologies, LLC called EasyFind and is available in the App Store or the developers website.
- EasyFind - Mac App Store Preview
- EasyFind - Developers Website
As you can see in the image below, EasyFind found the sample files created for testing. Simply select the ones you want to delete and then click Delete on its Toolbar to place the selected items in the Trash.
The nice feature of EasyFind is , with its various setting and controls, it's capable of making some searches that are not possible to perform in Finder while providing the user with a GUI interface, and without having to use Terminal.
Note that I'm not affiliated with the developer of EasyFind, just a happy user of the product.
- Open the folder containing the files in Finder
- Press Command-F
- Change the first pulldown to "Name"
- Change the second pulldown to "ends with"
- Enter your search criteria, e.g. "_s.png"
- Drag the files from the search result to the Trash
Option-clicking the "+" icon (at the end of the filter row) changes the icon to "…" which allows you to combine search operations, e.g. find files ending with both search terms in one search operation.