What command is used to list all files and directories in the current directory, where the second character of its name is a digit.

Can we use grep here?

  • Something like ls -d ?[0-9]*?
    – FedKad
    Feb 2, 2020 at 12:26
  • 1
    You need to differentiate between file name and file contents, here. ls e.g. is working on file names, grep on contents.
    – RudiC
    Feb 2, 2020 at 12:29
  • @FedonKadifeli can u explain all the content?
    – Arun Sanga
    Feb 2, 2020 at 12:30
  • 2
    As @RudiC asked from you: Do you mean the file whose name is to contain the digit, or whose content is to contain to digit? My comment, assumed that you are asking file names.
    – FedKad
    Feb 2, 2020 at 12:32
  • @FedonKadifeli I have some files like a2b, c2,d6,ef3.... We need to show all the files except ef3 because there is no Digit in second character
    – Arun Sanga
    Feb 2, 2020 at 12:34

1 Answer 1


If you want to list all files whose second character is a digit, you can use Bash wildcards like this: ?[0-9]*


  • ? represents any single character,
  • [0-9] represents any single character in the range 0..9, and finally
  • * represents any number of characters.

To list such files on the terminal you can use echo, ls, or any other command that will output its parameters. For example:

  • ls -d ?[0-9]*
  • echo ?[0-9]*

In the first case (ls), we need to add the -d parameter to list directories themselves, not their contents, in case that the file name we "match" is actually a directory.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .