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

as title: is the behaviour of .* to include . and .. defined in LSB or POSIX or some other specification?

share|improve this question
up vote 9 down vote accepted

Quoting from the Single Unix specification version 2, volume ”Commands & Utilities", §2.13.3:

If a filename begins with a period (.) the period must be explicitly matched by using a period as the first character of the pattern or immediately following a slash character. (…) It is unspecified whether an explicit period in a bracket expression matching list, such as [.abc] can match a leading period in a filename.

There is no exception that would make the second period in .., or the empty string following the only period in ., not matched by the wildcard in .*. Therefore the standard says that .* matches . and .., annoying though it may be.

The passage above describes the behavior of the shell (sh command). The section on the glob C library function refererences this passage.

The language is exactly the same in version 3, also known as POSIX:2001 and IEEE 1003.1-2001, which is what most current systems implement.

Dash, bash and ksh93 comply with POSIX. Pdksh and zsh (even under emulate sh) don't.

In ksh, you can make .* skip . and .. by setting FIGNORE='.?(.)', but this has the side effect of making * include dot files. Or you can set FIGNORE='.*', but then .* doesn't match anything.

In bash, you can make .* skip . and .. by setting GLOBIGNORE='.:..', but this has the side effect of making * include dot files. Or you can set GLOBIGNORE='.*', but then .* doesn't match anything.

share|improve this answer
note: bash doesn't always comply with POSIX. only when it's invoked as sh. – strugee Nov 26 '13 at 19:46

Probably you mean the functionality in bash expansion about globignore. By default the bash expansion match . and .. but reading the man:

The  GLOBIGNORE shell variable may be used to restrict the set of file names matching
   a pattern.  If GLOBIGNORE is set, each matching file name that also  matches  one  of
   the patterns in GLOBIGNORE is removed from the list of matches.  The file names ``.''
   and ``..''  are always ignored when GLOBIGNORE is set and not null.  However, setting
   GLOBIGNORE  to  a non-null value has the effect of enabling the dotglob shell option,
   so all other file names beginning with a ``.''  will match.  To get the old  behavior
   of  ignoring  file  names beginning with a ``.'', make ``.*''  one of the patterns in
   GLOBIGNORE.  The dotglob option is disabled when GLOBIGNORE is unset.

You can set the variable GLOBIGNORE=.:.. so when you tipe something like this:

rm -r * .*

you are removing only the current directory. The POSIX standard only specify that . is the current directory and .. in the parent of the current directory. The special meaning of .* is interpreted by bash or other shells (or programs like grep).

share|improve this answer

The Linux man-page references POSIX.2, 3.13.

share|improve this answer
Does the LSB require man, man glob or the man-pages to be present? I could not find man here (to my surprise). – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Nov 26 '13 at 19:18

As far as I can tell, the LSB 4.1 does not require bash and only sh.

For sh it follows POSIX (with one minor non-relevant extension).

share|improve this answer

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.