≡ Menu

Linux / Unix: Bash Find Matching All Dot Files

A dot-file is generally any file whose name begins with a full stop. In Linux or Unix like operating system it is also called as hidden file. How do I list all dot files in my home directory?

You can use the ls command to list all dot files in your current directory:

ls  .*

Sample outputs:

.bash_history  .bash_profile  .bashrc  .lesshst  .profile  .viminfo

.:
checkfs  checkroot  interfaces	interfaces.new	scripts  securedata.keyfile

..:
lost+found  root  root.user.only

.aptitude:
cache  config

.keychain:
nas01-csh  nas01-fish  nas01-sh

.ssh:
id_rsa	id_rsa.pub  known_hosts

.system_file_bakups:

.vim:

Please use the following syntax instead of .* for security reasons to avoid unexpected results:

ls  .[^.]*

Another option is to use the find command:
$ find . -name ".*"
OR
$ find . -name ".[^.]*"
Sample outputs:

.
./.bash_history
./.system_file_bakups
./.viminfo
./.bashrc
./.lesshst
./.ssh
./.profile
./.aptitude
./.bash_profile
./.vim
./.vim/.netrwhist
./.keychain

To list only matching dot files, enter:
$ find . -type f -name ".*"
Sample outputs:

./.bash_history
./.viminfo
./.bashrc
./.lesshst
./.profile
./.bash_profile
./.vim/.netrwhist

To list only matching dot directories, enter:
$ find . -type d -name ".*"
Sample outputs:

.
./.system_file_bakups
./.ssh
./.aptitude
./.vim
./.keychain
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 5 comments… add one }
  • kavinnath September 14, 2011, 2:50 pm

    . can be displayed using the command
    ls -a

  • Chris H October 13, 2011, 7:47 pm

    I always liked “ls .??*” as it excludes the “.” and “..” directories. Will miss any file/directory names which are “.” followed by a single character, though. Could get fancy, set the extglob shell extension (shopt -s extglob) and then:

    ls .!(.)*

  • muchrons October 14, 2011, 1:36 pm

    Another way to list “.” files and directories is “ls -d .*”

  • Rick Stanley October 15, 2011, 5:04 pm

    I think what most people want is either:
    ls -d .*
    To list all .files, and .directories, without listing .directory contents
    or
    ls -ld .*
    The same but in long format.

  • Bengt Grahn August 29, 2012, 2:03 pm

    This is all very well, but how do I get rid of the stupid “./.” at the beginning of the names? I want an output that looks like this:

    .system_file_bakups
    .ssh
    .aptitude
    .vim
    .keychain

    Nice and clean, no extra characters and only directory names!

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , , , , , , , , , , , ,