Linux: How to List Only Hidden Files And Directories

This post will guide you how to recursively list all hidden files and directories on Linux operating system. How do I show only hidden files in Linux. How do I only list hidden directories in a given directory on Linux.

List All Hidden Files with ls command


You can use ls command to list all files in a given directory in Linux, and the hidden files are not listed by default using ls command. If you want to list all hidden files in a directory using ls command, you need to pass -a or -al option to ls command. type the following command:

# ls -a

or

# ls -la

Outputs:

devops@devops-osetc:~$ ls
Desktop Documents Downloads examples.desktop fio.cc fio.txt Music Pict
devops@devops-osetc:~$ ls -a
. .bashrc .dmrc fio.cc .ICEauthority .mysql_hist
.. .cache Documents fio.txt .lesshst Pictures
.bash_history .config Downloads .gconf .local .profile
.bash_logout Desktop examples.desktop .gnupg Music Public

devops@devops-osetc:~$ ls -la
total 144
drwxr-xr-x 16 devops devops 4096 Dec 19 21:23 .
drwxr-xr-x 3 root root 4096 Jul 24 2017 ..
-rw------- 1 devops devops 4884 Dec 20 06:18 .bash_history
-rw-r--r-- 1 devops devops 220 Jul 24 2017 .bash_logout
-rw-r--r-- 1 devops devops 3791 Aug 1 2017 .bashrc
drwx------ 12 devops devops 4096 Aug 1 2017 .cache
drwx------ 14 devops devops 4096 Jul 24 2017 .config
drwxr-xr-x 2 devops devops 4096 Jul 24 2017 Desktop
-rw-r--r-- 1 devops devops 25 Jul 24 2017 .dmrc
drwxr-xr-x 2 devops devops 4096 Jul 24 2017 Documents
drwxr-xr-x 2 devops devops 4096 Jul 24 2017 Downloads
-rw-r--r-- 1 devops devops 8980 Jul 24 2017 examples.desktop
-rw-rw-r-- 1 devops devops 99 Jul 31 2017 fio.cc
-rw-rw-r-- 1 devops devops 20 Aug 1 2017 fio.txt
drwx------ 2 devops devops 4096 Jul 24 2017 .gconf
drwx------ 3 devops devops 4096 Dec 18 21:27 .gnupg
-rw------- 1 devops devops 2112 Dec 18 21:27 .ICEauthority
-rw------- 1 devops devops 36 Aug 1 2017 .lesshst
drwx------ 3 devops devops 4096 Jul 24 2017 .local
drwxr-xr-x 2 devops devops 4096 Jul 24 2017 Music
-rw------- 1 devops devops 614 Aug 1 2017 .mysql_history
drwxr-xr-x 2 devops devops 4096 Jul 24 2017 Pictures
-rw-r--r-- 1 devops devops 655 Jul 24 2017 .profile
drwxr-xr-x 2 devops devops 4096 Jul 24 2017 Public
-rw------- 1 devops devops 43 Aug 3 2017 .rediscli_history
-rw-r--r-- 1 devops devops 0 Jul 24 2017 .sudo_as_admin_successful
drwxr-xr-x 2 devops devops 4096 Jul 24 2017 Templates
drwxr-xr-x 2 devops devops 4096 Jul 24 2017 Videos
-rw------- 1 devops devops 3956 Dec 19 21:23 .viminfo
-rw-rw-r-- 1 devops devops 11 Dec 19 01:37 .vimrc
drwxrwxr-x 3 devops devops 4096 Dec 20 02:46 working
-rw------- 1 devops devops 119 Dec 18 21:27 .Xauthority
-rw------- 1 devops devops 82 Dec 18 21:27 .xsession-errors
-rw------- 1 devops devops 82 Jul 31 2017 .xsession-errors.old

If you want to only list all hidden files in a directory using ls command, you can use one of the following commands:

# ls -d .[!.]?*

or

# ls -l -d .[!.]?*

Outputs:

devops@devops-osetc:~$ ls -d .[!.]?*
.bash_history .dmrc .local .viminfo
.bash_logout .gconf .mysql_history .vimrc
.bashrc .gnupg .profile .Xauthority
.cache .ICEauthority .rediscli_history .xsession-errors
.config .lesshst .sudo_as_admin_successful .xsession-errors.old

devops@devops-osetc:~$ ls -l -d .[!.]?*
-rw------- 1 devops devops 4884 Dec 20 06:18 .bash_history
-rw-r--r-- 1 devops devops 220 Jul 24 2017 .bash_logout
-rw-r--r-- 1 devops devops 3791 Aug 1 2017 .bashrc
drwx------ 12 devops devops 4096 Aug 1 2017 .cache
drwx------ 14 devops devops 4096 Jul 24 2017 .config
-rw-r--r-- 1 devops devops 25 Jul 24 2017 .dmrc
drwx------ 2 devops devops 4096 Jul 24 2017 .gconf
drwx------ 3 devops devops 4096 Dec 18 21:27 .gnupg
-rw------- 1 devops devops 2112 Dec 18 21:27 .ICEauthority
-rw------- 1 devops devops 36 Aug 1 2017 .lesshst
drwx------ 3 devops devops 4096 Jul 24 2017 .local
-rw------- 1 devops devops 614 Aug 1 2017 .mysql_history
-rw-r--r-- 1 devops devops 655 Jul 24 2017 .profile
-rw------- 1 devops devops 43 Aug 3 2017 .rediscli_history
-rw-r--r-- 1 devops devops 0 Jul 24 2017 .sudo_as_admin_successful
-rw------- 1 devops devops 3956 Dec 19 21:23 .viminfo
-rw-rw-r-- 1 devops devops 11 Dec 19 01:37 .vimrc
-rw------- 1 devops devops 119 Dec 18 21:27 .Xauthority
-rw------- 1 devops devops 82 Dec 18 21:27 .xsession-errors
-rw------- 1 devops devops 82 Jul 31 2017 .xsession-errors.old

Recursively List All Hidden Files and Directories


If you want to list all hidden files recursively in a given directory, you need to use find command to achieve the result.

For example, you need to show all hidden files in /home/devops directory and its sub-directories, you can use the following command:

# find /home/devops -name ".*" -print

Outputs:

devops@devops-osetc:~$ find /home/devops -name ".*" -print
/home/devops/.sudo_as_admin_successful
/home/devops/.gnupg
/home/devops/.profile
/home/devops/.bash_history
/home/devops/.bash_logout
/home/devops/.lesshst
/home/devops/.mysql_history
/home/devops/.cache
/home/devops/.gconf
/home/devops/.dmrc
/home/devops/.xsession-errors.old
/home/devops/.local
/home/devops/.local/share/.converted-launchers
/home/devops/.vimrc
/home/devops/.xsession-errors
/home/devops/.rediscli_history
/home/devops/.config
/home/devops/.viminfo
/home/devops/.bashrc
/home/devops/.ICEauthority
/home/devops/.Xauthority

If you only want to list all hidden normal files, type the following command:

# find /home/devops -type f -name ".*" -print

Outputs:

devops@devops-osetc:~$ find /home/devops -type f -name ".*" -print
/home/devops/.sudo_as_admin_successful
/home/devops/.profile
/home/devops/.bash_history
/home/devops/.bash_logout
/home/devops/.lesshst
/home/devops/.mysql_history
/home/devops/.dmrc
/home/devops/.xsession-errors.old
/home/devops/.local/share/.converted-launchers
/home/devops/.vimrc
/home/devops/.xsession-errors
/home/devops/.rediscli_history
/home/devops/.viminfo
/home/devops/.bashrc
/home/devops/.ICEauthority
/home/devops/.Xauthority

If you want to only show all hidden directories, type the following command:

# find /home/devops -type d -name ".*" -print

Outputs:

devops@devops-osetc:~$ find /home/devops -type d -name ".*" -print
/home/devops/.gnupg
/home/devops/.cache
/home/devops/.gconf
/home/devops/.local
/home/devops/.config

 

You might also like:

Sidebar



back to top