If you are working on unix based system (for any reason), you know that you will need “ls” command more than often. Not anyone would disagree that “ls” is one of the most widely used command in any unix based system.
However one of the thing which got me surprised is the lack of option with “ls” which would list *only* hidden file (or directory). Obviously I am not interested in getting the result which includes the famous “.” and “..” (current and parent directory respectively).
When trying with the option “a”
<kunalkumar@kspace>ls -a ./ ../ .data .dump/ src test
As expected, the list included all the files present in the directory (including hidden files as well). However as I was interested only in getting the name of hidden files, I executed
<kunalkumar@kspace>ls -a .* .data .: ./ ../ .data .dump/ src test ..: ./ ../ test/ .dump: ./ ../ dump.1 dump.2
Oouch! Because of the “.*” for file name, it traversed the directories present and hence the above result. So let’s ask “ls” not to traverse directories present and just list the name
<kunalkumar@kspace>ls -ad .* ./ ../ .data .dump/
Ok. Still the result includes “.” and “..” which I did not want. My attempt also included
<kunalkumar@kspace>ls -ad .* ./ ../ .data .dump/ <kunalkumar@kspace>ls -a | grep "^\." ./ ../ .data .dump/
At the end, I realized there is an option with “ls” which directs it to ignore “.” and “..” while listing and finally,
<kunalkumar@kspace>ls -A | grep "^\." .data .dump/
However, I still wonder why there is not direct option with “ls” which only list the name of hidden files (excluding “.” and “..” .) Probably because “.” and “..” are also considered as hidden and hence the output.

