Selecting file names in a shell - one word or another
Archive - Originally posted on "The Horse's Mouth" - 2008-02-02 07:29:25 - Graham Ellis
If you want to select all file names that include the words "cat" or "dog" in them with file name matching, you can do so using curly braces - that's supported by most modern shells as part of what is known as "globbing".
Here's an example - I've just been copying images off my digital camera and I wanted all files from 28th January, 31st January and 1st February - so file names starting P128, P131 and P201, and this is what I wrote:
Sometimes, there is confusion between square brackets and curly braces in file name matching. If I had written [128,131,201]
I would have been looking for any ONE character from the list in the brackets - so that's a 0 1 2 3 8 or comma (and the specification of the comma 1 and 2 several times would have shown that I didn't realise what I was doing. And if I had written [128][131][201]
then I would have been looking for a 1 2 or 8 followed by a 1 or 3 (or 1!) followed by s 2 a 0 or a 1