Bash Shell: Display All Hidden Dot Files In a Directory

by Vivek Gite on October 29, 2006 · 1 comment

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

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 1 comment… read it below or add one }

1 James April 2, 2009

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.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 2 + 14 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: