UNIX 'ls' command - wildcard 'OR' operator

Nossidge picture Nossidge · Jun 22, 2012 · Viewed 15.7k times · Source

I have a directory with timestamped files in the format:

processAlpha20120618.txt
processAlpha20120619.txt
processAlpha20120620.txt
processBeta20120618.txt
processBeta20120619.txt
processBeta20120620.txt
... etc.

I want a list of these for specific dates. Something like this:

ls -l *201206[19|20|21]*

Obviously the above doesn't work, but you can see what I was trying to achieve. I want to match anything where the string "201206" is followed by either "19", "20" or "21".

I know that this is possible using grep or find, I just wondered if it could be done using ls.

Answer

Andrew Stubbs picture Andrew Stubbs · Jun 22, 2012

Providing you're wanting to match exact dates (which it appears you are), the way to so with bash expansion is:

ls -l *201206{19,20,21}*