Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I try to match all dot files in a directory with .* it seems to have a nasty side-effect: besides matching all (real) files and directories, it matches . and ...

bash-3.2$ mv test/.* dest/
mv: rename test/. to dest/.: Invalid argument
mv: test/.. and dest/.. are identical

This seems really weird, since they are basically 'fake' directories, just there to make relative paths easy. They are not part of the contents of a directory, and I don't ever want them matched when I try to move the contents of one directory to another directory. I can't think of any scenario where I would want them matched by .*.

So how can I turn this off? (Besides using Z shell, which is not always available, and which may not be the shell in use by someone running a function I've written.)

share|improve this question
up vote 9 down vote accepted

You can use the GLOBIGNORE bash variable.

              A colon-separated list of patterns defining the set of filenames
              to be ignored by pathname expansion.  If a filename matched by a
              pathname  expansion  pattern also matches one of the patterns in
              GLOBIGNORE, it is removed from the list of matches.


       .......................-.  The file names ``.''  and ``..''  are always
       ignored  when GLOBIGNORE is set and not null.  

So if you set


then path/.* will not match . and .., as you ask.

share|improve this answer
Wouldn't GLOBIGNORE=.:.. more succinctly accomplish the same thing? Or is there a subtle difference I'm missing? – iconoclast Jun 18 '12 at 14:50

A glob pattern would be .[^.]* -- it matches something with at least 2 characters where the 2nd char is not a dot.

Documentation for filename pattern matching is in the bash man page or here: http://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching

Jonathan Callen raises a good point. You can use a fairly simple extended pattern

shopt -s extglob
ls -d .!(.|)
share|improve this answer
That will miss files named like ..install.cmd (A real file I've seen in the wild). – Jonathan Callen Jun 13 '12 at 20:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.