How can I make bash not match `.` and `..` with `.*`

When I attempt to match all dot files in a directory site with .* it appears to have a horrible side - result: besides matching all (actual) files and also directory sites, it matches . and also ...

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

This appears actually unusual, given that they are primarily 'phony' directory sites, simply there to make loved one courses very easy. They are not component of the materials of a directory site, and also I do not ever before desire them matched when I attempt to relocate the materials of one directory site to an additional directory site. I can not consider any kind of circumstance where I would certainly desire them matched by .*.

So just how can I transform this off? (Besides making use of Z shell, which is not constantly readily available, and also which might not be the shell in operation by a person running a function I've created.)

2022-06-07 14:38:45
Source Share
Answers: 2

You can make use of 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.

and also

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

So if you set


after that path/.* will certainly not match . and also .., as you ask.

2022-06-07 15:11:33

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

Documents for filename pattern matching remains in the bash male web page or below:

Jonathan Callen elevates an asset. You can make use of a rather straightforward extensive pattern

shopt -s extglob
ls -d .!(.|)
2022-06-07 15:07:02