How to recursively list all hidden files and directories?

32,438

Solution 1

If using GNU find, you can do

find /path -path '*/.*' -ls | tee output-file

Edit

To avoid to show non-hidden items contained in hidden directories

find /path -name '.*' >output-file

(as noted, tee could be avoided if you do not need to see the output, and -ls option should be used only if required).

Solution 2

To list the hidden files and directories in the current directory, including . and ..:

echo .*

To list the hidden files and directories in the current directory and its subdirectories recursively:

find . -name '.*'

If you want to save the results to a file, use a redirection:

find . -name '.*' >output-file.txt

Solution 3

With zsh (using the glob qualifier D):

print -rl ./**/.*(D)

To include non-hidden files in hidden directories:

setopt extendedglob
print -rl ./**/*~^*/.*(D)
Share:
32,438

Related videos on Youtube

lukasz
Author by

lukasz

Updated on September 18, 2022

Comments

  • lukasz
    lukasz over 1 year

    I want to list all hidden files and directories and then save result to file.

    Is there any command for this?

  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 12 years
    This also lists the contents of hidden directories, which isn't what the question asks for (probably — it is a little ambiguous).
  • enzotib
    enzotib over 12 years
    @Gilles: indeed it is ambiguous. Edited the answer
  • Stéphane Chazelas
    Stéphane Chazelas over 8 years
    Note that the first one is not GNU-specific. -path is POSIX since 2008. -ls is not standard but quite common.