?[0-9]*
only expands to names in the current directory that has a digit as their second character. ls
, when getting a directory name, will obviously show the contents of that directory, which means that you will have to tell ls
to not not do that.
You do this with ls -d
:
ls -d -- ?[0-9]*
or
ls -d ./?[0-9]*
The --
and ./
will stop ls
from interpreting the first character of the filename as an option if it starts with a dash.
If you are only interested in non-directories (and want to also weed out symbolic links to directories), then there are two immediately obvious ways of doing this.
Use a shell loop, testing each name to see whether it's a directory or not and display the name if it isn't:
for name in ?[0-9]*; do
[ ! -d "$name" ] && printf '%s\n' "$name"
done
To include files that start with a dot (hidden files), a shell may have a dotglob
shell option that you may set before the loop (shopt -s dotglob
in bash
).
Use find
to look for non-directories (and weed out symbolic links to directories) in the current directory:
find -L . -maxdepth 1 ! -type d -name '?[0-9]*'
The -L
option to find
makes -type d
refer to the target of any symbolic link (if the current pathname is a symbolic link).
[0-9]
matches on much more than 0123456789.[[:digit:]]
should be OK, use[0123456789]
to be sure. – Stéphane Chazelas Jun 18 '18 at 05:49?[0-9]*
file whose second character is not a digit. That's a misfeature introduced by the Bourne shell, fixed again in zsh, or in bash with the failglob option. – Stéphane Chazelas Jun 18 '18 at 05:51