Bash Shell: Display All Hidden Dot Files In a Directory

Q. How do I display only hidden (dot) file names under Linux / UNIX operating systems?

A. If you would like to see only hidden file in the current directory, use ls command.

Bash list only hidden files

Use ls -a command to display all hidden dot files. -a option do not hide entries starting with .
$ ls -a

Output:

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 files including hidden dot files. To just display dot files use command:
$ ls -a | egrep '^\.'
$ ls -A | egrep '^\.'

You can create an alias and put into .bash_profile or .bashrc file
$ vi .bash_profile
Append following line
alias lh='ls -a | egrep "^\."'

Save and close the file. Now you can use lh command (read as alias) to display only hidden (dot) files:
$ lh

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 1 comment… read it below or add one }

1 James 04.02.09 at 5:17 pm

If you use grep you will lose formatting (multi-column) and colour.

If you use “ls -Ad .*”, it will show you all hidden (dot) files and retain the formatting and colour. The “-d” argument is used to only show the top-level files and not contents of hidden directories.

Thanks for the tip, I didn’t know about the -A argument.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , ,

Previous post: Monitor Linux user activity in real time

Next post: Host a domain without CPanel or Plesk Control Panel