Search code examples
unixgreppipelsfilepattern

Unix command to list all the files and directories in the current directory whose second character is a digit


My code for this is ls | grep .[0-9]*

And the output is showing as

d2
d4
di3
dir1
f1
f2
fil4
file3
g2t
g3t

The expected output is

d2
d4
f1
f2
g2t
g3t

I know i can directly use ls ?[0-9] but then my output order is different

f1  f2  g2t  g3t

d2:

d4:

Solution

  • Okay this worked ls -d ?[0-9]*