how to glob every hidden file except current and parent directory
You can use the GLOBIGNORE
variable to hide the .
and ..
directories. This does automatically also set the dotglob
option, so *
now matches both hidden and non-hidden files. You can again manually unset dotglob
, though, this then gives the behavior you want.
See this example:
$ ls -a
. .. a .a ..a
$ GLOBIGNORE=".:.."
$ shopt -u dotglob
$ echo * # all (only non-hidden)
a
$ echo .* # all (only hidden)
.a ..a
The first glob below requires a leading dot and at least one additional non-dot character. These two globs together will match any possible hidden files, including files with more than one leading dot, but not .
or ..
, which is exactly what you asked for.
ls -ld .[!.]* ..?*
Are you just looking for files? Are you in a position to use find
?
Something like (assuming GNU find
):
find . -mindepth 1 -maxdepth 1 -name ".*" -printf "%P\n"