1

I have a ton of files - TOSEC ROM sets - on my Mac (El Capitan) that have filenames suffixed with a tag in square brackets - for example

Manic Miner (1983)(Bug-Byte Software)[a]
Manic Miner (1983)(Software Projects)[a]

I'd like to search for these files, with the aim of moving and/or deleting them.

If I try to search for the files using Spotlight:

enter image description here

... no files are found.

If I try searching for them via Terminal:

ls *[a]*.*

... I get a list of all the files in the directory.

What's the best way of finding all files with [a] in the filename, and moving and/or deleting them? Is there a way to encapsulate the [ and ] so a Spotlight search will work?

  • 1
    I'd have a look at EasyFind on the app store, freeware. Very comprehensive search options, though no indexing, so it's slower than other methods – Tetsujin Jun 19 '16 at 11:40
  • Thanks - definitely a useful tool, I can see it coming in handy. – KenD Jun 19 '16 at 22:00
1

If you want to find and delete files that have [a] in the name you can use the following command in a Terminal:

find . -name "*\[a\]*" -print0 | xargs -0 echo rm

The above command will find and echo the rm command with the filenames containing [a]. The echo portion of the command line is added as a safety precaution. Run the command to see that you are okay with its output and then run it again without echo in the command line to actually delete the files the command outputs.

The shell treats the square brackets differently and as such they need to be escaped with a backslash \ and why the output of ls was not what you wanted.

  • 1
    @KenD, Glad it worked for you. By the way the app mentioned by Tetsujin, EasyFind, is an excellent and handy app to have when you want to do some searching from a GUI versus the command line. – user3439894 Jun 19 '16 at 22:08
1

In Terminal, use \ to escape any character:

ls *\[a\]*

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .