I have files like file123.txt
, file.txt
but when I run ls -l file[0-9]*.txt
, I'm only getting file123.txt
.
How do I get both files? I thought *
means "0 or more", but it's not working. (I'm using ksh, if relevant).
I have files like file123.txt
, file.txt
but when I run ls -l file[0-9]*.txt
, I'm only getting file123.txt
.
How do I get both files? I thought *
means "0 or more", but it's not working. (I'm using ksh, if relevant).
It is Pattern matching, not a regular expression.
[0-9]
and *
are distinct patterns. *
is not a modifier as in a regular expression.
* Matches any string, including the null string.
[...] Matches any one of the enclosed characters.
You may use a pattern-list where the *
is a prefix to the enclosed pattern-list
*(pattern-list) Matches zero or more occurrences of the given patterns.
ls file*([0-9]).txt
would be the syntax for zero or more digits.
$ ls file*.txt
file123.txt filea.txt file.txt
$ ls file*([0-9]).txt
file123.txt file.txt
For details see 'File Name Generation' in man ksh
.
Some more examples can be found here KSH93 Extended Patterns
You're adding a number filter, just remove this to return files that start with 'file' and end with '.txt':
ls -l file*.txt