Search code examples
stringshellunixwildcardls

UNIX 'ls' command - wildcard 'OR' operator


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.


Solution

  • ls does not do this - the shell expands * etc and then passes them to ls as arguments.

    Look at the documentation for the shell - it is call globbing