It's not news that the shell turns
.* (dot asterisk)
into every name in the current directory that starts
with a dot: .login, .profile, .bin (I name my directory
that way), and so on - including
Also, many people know that the shell turns
into a list of the dot files in subdirectories: foo/.exrc,
foo/.hidden, bar/.xxx-as well as foo/., foo/..,
bar/., and bar/.., too.
(If that surprises you, look at the wildcard pattern closely - or try it
on your account with the echo command:
What if you're trying to match just the subdirectory names, but not the
files in them?
The most direct way is:
*/.-that matches foo/., bar/.,
and so on.
The dot (
.) entry in each directory
so you can use it wherever you use the directory name.
For example, to get a list of the names of your subdirectories, type:
ls -d */.bar/. foo/.
ls -d */bar/ foo/
(The shell passes the slashes (
/) to ls.
So, if you use the ls
to put a slash after directory
names, the listing will show two slashes after each directory
When matching directory names that start with a dot,
the shells expand the
.*/. and pass the result to
really don't need the ls
The -a is useful only when
you ask ls (not the shell) to read a directory and list the entries in it.
You don't have to use ls, of course.
command will show the same list more simply.
Here's another example: a Bourne shell loop that runs a command in each subdirectory of your home directory:
for dir in $HOME/*/. do cd $dir ...Do something... done
That doesn't take care of subdirectories whose names begin with a dot, like my .bin-but article 15.5 shows a way to do that too.
Article 21.12 shows a related trick that doesn't involve the shell or wildcards: making a pathname that will match only a directory.