Bash Shell: Display All Hidden Dot Files In a Directory

How do I display only hidden (dot) files names under Linux / UNIX / Apple OS X / *BSD family operating systems?

You can view only hidden files or directories in the current directory, using ls command and shell patterns.

Bash list only hidden files

Use ls -a command to display all hidden dot files. The -a option do not hide entries starting with . in the current directory or given path. Type the following command:

$ ls -a

Sample outputs:

gimp.txt                                                .viminfo
.gnome                                                  vivek-feed.xml
.gnome2                                                 .vlc
.gnome2_private                                         .vmware
.gnome-desktop                                          .wine
.gnome_private                                          Woh Lamhe - 2006-MP3-VBR-128Kbps
go.html                                                 .Xauthority

As you see output includes all the files including hidden dot files. To just display dot files use any one of the following command:
$ ls -a | egrep '^.'
$ ls -A | egrep '^.'

OR
$ ls -l ~/.[^.]* | less
OR
$ ls -ld ~/.[^.]*
OR
$ ls -l ~/.??*
OR
$ ls -ld ~/.??*
Sample outputs:

You can create an alias and put into your ~/.bash_profile or ~/.bashrc file:
$ vi ~/.bash_profile
Append the following line:
alias lh='ls -a | egrep "^."'
OR
alias lh='ls -l .??*'
alias lhd='ls -ld .??*'

Save and close the file. Now you can use lh or lhd commands to display only hidden dot files under Unix like operating systems.
$ lh
OR
$ lhd
Sample outputs:

Fig.01: HowTo: use terminal ls command to see hidden dot files

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.