List all file whose 3rd char is digit

list all file whose 3rd char is digit (or Nth position is digit)

what will be the required command?

ls ??[0-9]*
2 Likes

With an ERE (egrep or grep -E)

ls | egrep '^.{2}[0-9]'

^ beginning of line
.{2} a character 2 times
[0-9] a character in the range 0-9

Within " " the shell substitutes $var or ${var} by its value, before it hands it to the egrep

num=2
ls | egrep "^.{$num}[0-9]"
1 Like

Slightly different approach:

echo ??[0-9]* | tr " " "\n"
1 Like
compgen -f -X '!??[0-9]*'

The simple "arguments to lines" command is printf

printf "%s\n" ??[0-9]*

But commands can overflow with "too many arguments".

1 Like