If you want to match all files in a directory whose names do not start
with a dot (
.), it's easy: just use an asterisk (
But what about files that do start with a dot?
That's harder because dot-asterisk (
.*) matches the directory links
.. that are in every directory; you
usually won't want to match those.
The Korn and some Bourne shells, as well as bash, let you use the
.[!.]* to match all dot files, where
means "anything but a dot."
Otherwise, what can you do?
You can use
.??*, which matches all filenames that start with a
dot and have at least two characters, but that doesn't match filenames
like .a with just one character after the dot.
Here's the answer:
That expression matches all filenames whose second character is in the
The range starts with CTRL-a
^A is an actual CTRL-a character, not the two characters
A) and runs through a dash (
Then it covers the range from zero (
0) through DEL or
(make by pressing your
key; you may have to type
or a backslash (
Yuck - that's sort of complicated.
To make it easy, I set that sequence in a shell variable named dots
set dots=".[`echo Y-0-Z | tr YZ \\001\\177`]" csh dots=".[`echo \\\\001-0-\\\\0177`]*" sh, etc. dots=".[`echo Y-0-Z | tr YZ \\001\\177`]*" sh with old echo
turns the expression
into the range with CTRL-a and DEL that we want.
That keeps ugly, unprintable characters out of the .cshrc file.
So, for example,
I could move all files out of the current directory to
another directory by typing:
mv * $dots