The names of hidden files start with .
(dot), there are none that start with b
. To list names starting with .b
use
$ ls .b*
This will also list the contents of any directory whose name starts with .b
. Note that -a
is not needed here as we explicitly give a filename pattern for the shell to match. Since the pattern starts with .
(dot), it will match hidden files. The expanded pattern will be given to ls
for processing.
To avoid listing the contents of directories, use
$ ls -d .b*
The above solutions will give an error if no name matches the pattern.
To only list the names of regular files whose names start with .b
, use
$ for name in .b*; do test -f "$name" && printf '%s\n' "$name"; done
To get the output in a similar way as with plain ls
(note that column
is a non-standard utility):
$ for name in .b*; do test -f "$name" && printf '%s\n' "$name"; done | column
The last couple of solutions will not print anything of no name matches the pattern.
ls -a | grep .b*
should do I think – ddnomad Feb 23 '17 at 9:24grep
ing anls
output is unnecessarily complex, when you can specify the pattern withls -a -d .b*
- note that you need-d
for not listing contents of the results. Also thatgrep
will show files like123.bWRONG
. – Fiximan Feb 23 '17 at 9:35man ls
. I suggest you read it. – terdon♦ Feb 23 '17 at 9:54