How to use _one_ shell globbing expression to list all files (of course hidden files too!)?
*
does match a .
character.
It simply doesn't match .
when it is the first character of the name. This provides a so-called "dot file" mechanism for "hiding" files.
In zsh
:
Set the GLOB_DOTS
shell option. This is in § 14.8 of the zsh
user manual. Note that .
and ..
are always excluded even if this option is turned on.
In bash
:
Set the dotglob
shell option. This is in § 3.5.8 of the bash
user manual. Note that setting the GLOBIGNORE
shell variable implicitly sets dotglob
; that bash
(unlike zsh
) doesn't automatically exclude .
and ..
when dotglob
is enabled; but that bash
will do that when GLOBIGNORE
is set. So setting GLOBIGNORE=.
will have the effect of turning on dotglob
and excluding .
and ..
.
In GNU find
:
Don't do anything. As of findutils
4.2.2, the globbing for -name
and -iname
already matches names with dots as the first character. This is in § 2.1.1 of the findutils
user manual.
If you don't want to change any options, any of these will do:
ls -ld {,.}*vim*
ls -ld *vim* .*vim*
find . -maxdepth 1 -name "*vim*"
In bash, enable the dotglob option:
shopt -s dotglob
By default, hidden files are hidden to not cause surprises and annoyances – for example, you run ls
in your home directory, see some files from last month, try to remove them with rm *net*
and unknowingly nuke your carefully written .nethackrc
.