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.
This wildcard is used to represent any character, or even no characters at all! Instead of listing all the files in the directory with “ls”, when the command “ls *. c” was used the shell expanded the * to include all files, but you specified that you only wanted to find all files that ended with the “. c” at the end.
Wildcards (also referred to as meta characters) are symbols or special characters that represent other characters. You can use them with any command such as ls command or rm command to list or remove files matching a given criteria, receptively.
Their UNIX representation are listed for informational purposes only: Asterisk (*) – matches any string, including an empty string. Question mark (?) – matches a single character.
If ls is being passed an argument called * , it will look for a file or directory called * in the current directory and list it just like any other.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With