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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIf you want to list all files whose second character is a digit, you can use Bash wildcards like this: ?[0-9]*
where:
?
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.
ls -d ?[0-9]*
?ls
e.g. is working on file names,grep
on contents.