That's to work around a bug/misfeature in shells other than
fish and the descendants of the Forsyth shell (including
pdksh and derivatives)¹, whereby the expansion of the
.* glob includes
.. (on systems (most, unfortunately) where
readdir() returns them)
With those shells,
chmod -R og-rwx .*
for instance would recursively remove rwx permissions to the current (
.) and parent (
..) directories instead of just the hidden files and directories in the current directory.
It's particularly bad for commands that do things recursively or act on directories like
chown -R .*,
grep -r blah .* but it's still annoying for most other commands and I can't think of any commands for which you'd want to have those
.. included in the list of files passed to them.
A safeguard had to be added to the
rm utility to work around that misfeature as too many people were tripping on
rm -rf .*.
* added, it's also used to pass all files (hidden or not) as arguments to a command (
cmd -- .[!.]* ..?* *), for which you'll find other workarounds depending on the shell.
.[^.]* glob (
.[!.]* in Bourne/POSIX shells) excludes
. (as it matches on filenames with at least two characters) and
.. (as the second character is
. which doesn't match
[^.]), but also excludes files like
..foo, for which you need the second glob
.. are tools for directory traversal, it's a mistake that they should be listed like ordinary files. POSIX requires them to be understood in path components (like in
stat("foo/../bar")) but not necessarily be implemented as directory entries nor included in
Still, most systems still do implement those like in the early Unices as hard links, and most of those that don't will still fake entries for them in the output of
bash, an alternative is to turn the
dotglob option on and use:
chmod -R og-rwx [.]*
(though beware that if there's no non-hidden file, it could change the permissions of the
[.]* file unless you had the
failglob option on to mimic the behaviour of
As a history note, filenames starting with
. being hidden files were born from a coding mistake from someone trying to skip
.. in the first place. It's ironical that when trying to do things with hidden files we would run into the same problem.
¹ see also the
globskipdots option in bash 5.2+