You want to see only hidden (dot) files in a directory to edit a file you forget the name of or remove obsolete files.
ls -a shows all files, including normally hidden ones, but that is often too noisy, and ls -a .* doesn’t do what you think it will.
Use ls -d along with whatever other criteria you have.
ls -d .*
ls -d .b*
ls -d .[!.]*
Or construct your wildcard in such a way that . and .. don’t match.
$ grep -l 'PATH' ~/.[!.]*
Due to the way the shell handles file wildcards, the sequence .* does not behave as you might expect or desire.
The way filename expansion or globbing works is that any string containing the characters *, ?, or [ is treated as a pattern, and replaced by an alphabetically sorted list of file names matching the pattern.
* matches any string, including the null string, while ? matches any single character. Characters enclosed in [ ] specify a list or range of characters, any of which will match.
There are also various extended pattern-matching operators that we’re not going to cover here (see “Pattern-Matching Characters” and “extglob Extended Pattern-Matching Operators” in Appendix A).
So *.txt means any file ending in .txt, while *txt means any file ending in txt (no dot). f?o would match foo or fao but not fooo.
So you’d think that .* would match any file beginning with a dot.
The problem is that .* is expanded to include . and .., which are then both displayed.
Instead of getting just the dot files in the current directory, you get those files, plus all the files and directories in the current directory (.), all the files and directories in the parent directory (..), and the names and contents of any subdirectories in the current directory that start with a dot.
This is very confusing, to say the least.
You can experiment with the same ls command with -d and without, then try echo .*.
The echo trick simply shows you what the shell expanded your .* to. Try echo .[!.]* also.
.[!.]* is a filename expansion pattern where [ ] denotes a list of characters to match, but the leading ! negates the list.
So we are looking for a dot, followed by any character that is not a dot, followed by any number of any characters.
You may also use ^ to negate a character class, but ! is specified in the POSIX standard and thus is more portable.