I’m trying to list files using regex but it’s not getting listed as expected.
# ls test*.tgz
test-2012_07_17_11_23_45.tgz
But when I use little drilled regex it’s failing.
# ls test-[0-9]{4}_*.tgz
ls: cannot access test-[0-9]{4}_*.tgz: No such file or directory
# ls test-[0-9]\{4\}_*.tgz
ls: cannot access test-[0-9]{4}_*.tgz: No such file or directory
# ls "test-"[0-9]\{4\}"_"*".tgz"
ls: cannot access test-[0-9]{4}_*.tgz: No such file or directory
Any pointers would be helpful.
bash does not support glob expansion via regular expressions. You need to use glob syntax or extglob syntax, neither of which allows {4} for number of occurrences.
Try `ls | pcregrep’ or something like that instead, or provide more info on what you are trying to do.