tags:

views:

32

answers:

2

i am looking to search for in dir ...

a2010-02-10

how to search the ls all dir in with date format

ls -d *(\d+)-(\d+)-(\d+)

its not working like perl

what is the right format

+3  A: 

Your regex appears to be correct, but bash doesn't support full regular expressions. It supports wildcards, which can't always work the same way. Try this:

ls -d | grep -E '(\d+)-(\d+)-(\d+)$'

And really, the (\d+) groups could be replaced with just \d+.

If you prefer a pure-bash solution, try this:

ls -d *[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]

You can simplify that to be less exact if desired:

ls -d *[0-9]*-[0-9]*-[0-9]*

But I'd go for using grep because it is a lot clearer what you want. You could make it even clearer:

ls -d | grep -E '\d{4}-\d{2}-\d{2}$'
jnylen
A: 

With shopt -s extglob, you can do:

ls -d *+([0-9])-+([0-9])-+([0-9])
Dennis Williamson