Linux / Unix: Find And List All Hidden Files Recursively

by on April 7, 2014 · 3 comments· LAST UPDATED April 7, 2014

in , , ,

I am a new Unix system shell user. I need to find and list all hidden files including directories on a Linux or Unix-like system. How can I recursively list all hidden files and directories? How do I save result in a text file?

You need to use the find command to list all hidden files recursively on a Linux or Unix like systems.
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsNone
Estimated completion time2m

Syntax: Recursively list all hidden files and directories on Linux/Unix

The basic syntax is as follows:

find /dir/to/search/ -name ".*" -print

OR

find /dir/to/search/ -name ".*" -ls

OR search only hidden files:

find /dir/to/search/ -type f -iname ".*" -ls

OR search only hidden directories:

find /dir/to/search/ -type d -iname ".*" -ls

OR

find /dir/to/search -path '*/.*' -print
find /dir/to/search -path '*/.*' -ls

In this example, search $HOME for all hidden files and dirs:

 
find $HOME -name ".*" -ls
 

Sample outputs:

6553607    4 -rw-r--r--   1 admi     admi          100 Sep 22  2004 ./.cshrc
6553664    4 -rw-------   1 admi     admi         1024 Nov 17 04:40 ./.rnd
6553604    4 -rw-r--r--   1 admi     admi           18 May 20  2009 ./.bash_logout
6553665    4 drwx------   2 admi     admi         4096 Dec 18  2012 ./.gnupg
6553671    0 -rw-------   1 admi     admi            0 Dec 18  2012 ./.gnupg/secring.gpg
6553669    0 -rw-------   1 admi     admi            0 Dec 18  2012 ./.gnupg/pubring.gpg~
6553673    4 -rw-------   1 admi     admi          899 Dec 18  2012 ./.gnupg/pubring.gpg
6553667    8 -rw-------   1 admi     admi         7856 Dec 18  2012 ./.gnupg/gpg.conf
6553668    4 -rw-------   1 admi     admi         1200 Dec 18  2012 ./.gnupg/trustdb.gpg
6553602   20 -rw-------   1 admi     admi        17462 Apr  7 10:55 ./.bash_history
6553610    4 drwx------   3 admi     admi         4096 Jan 16  2013 ./.config
6553660    4 drwx------   2 admi     admi         4096 Jan 16  2013 ./.config/htop
6553681    4 -rw-r--r--   1 admi     admi          597 Apr 11  2013 ./.config/htop/htoprc
6553723   12 -rw-------   1 admi     admi         9629 Mar 30 23:56 ./.viminfo
6553615    4 drwxr-xr-x   3 admi     admi         4096 Nov 29  2012 ./.original-configs

To save the results to a file called foo.txt, use a redirection as follows:

 
find $HOME/projects/ -name ".*" -ls > foo.txt
cat foo.txt
 

See find(1) command man page for more information.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 3 comments… read them below or add one }

1 Vinoth April 8, 2014 at 5:15 am

Please try below with ls command.

ls -lRa > List.txt

Reply

2 Chris F.A. Johnson April 8, 2014 at 8:05 pm

There is no point to using -iname since there are no alpha characters to match, and since it is non-standard, it will only work with GNU find.

Reply

3 daniel andrade April 10, 2014 at 2:51 pm
find . -name ._\* -print0 | xargs -0 rm -f

to remove all hidden files recursively! :D

Reply

Leave a Comment

Tagged as: , ,

Previous Faq:

Next Faq: