It's not news that the shell turns
into every name in the current directory that starts
with a dot: .login
(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
-as well as foo/.
, and bar/..
(If that surprises you, look at the wildcard pattern closely - or try it
on your account with the echo
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/.
and so on.
The dot (
) entry in each directory
is a link to the directory itself (18.2
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 */.
to list the names of directories, not their contents.)
With some C shells (but not all), you don't need the trailing dot (
ls -d */
(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
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/*/.
That doesn't take care of subdirectories
whose names begin with a dot,
like my .bin
shows a way to do that too.
shows a related trick that doesn't involve the shell or wildcards:
making a pathname
that will match only a directory.