The command
ls .*
when run gives as output the following :
- All the files in the current directory starting with a . (hidden files)
- All the files in the hidden directories present in the current directory
- All the files in the current directory
- All the files in the parent directory
Why does the command
ls *.
not display :
- All the files in the current directory
- All the files in the parent directory
Reason I am thinking so is : The regular expression *. should match both . and .. So ls should be run on both and thus the output which I am expecting should be displayed
Best Answer
It's because
*
doesn't match files starting with a.
by default. Consider the following directory:Let's see what each of the globs you used expands to:
As you can see, the
*
does not include files or directories starting with.
so both./
and../
are ignored. The same thing happens with yourls
example. Inbash
, you can change this with thedotglob
parameter, which will cause*
to expand to dotfiles as well (but not to.
or..
, those are still ignored):Other shells behave differently. For example
zsh
also ignores the.
and..
when using.*
: