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

Is there any command for this?


If using GNU find, you can do

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


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).

  • 2
    Or with >instead of | tee, if one doesn't want to see the whole output on the terminal. – rozcietrzewiacz Aug 7 '11 at 13:25
  • You also don't need -ls on this, that might be extra messy information to parse thought. – Caleb Aug 7 '11 at 17:03
  • This also lists the contents of hidden directories, which isn't what the question asks for (probably — it is a little ambiguous). – Gilles Aug 7 '11 at 19:53
  • @Gilles: indeed it is ambiguous. Edited the answer – enzotib Aug 7 '11 at 20:00
  • Note that the first one is not GNU-specific. -path is POSIX since 2008. -ls is not standard but quite common. – Stéphane Chazelas Aug 25 '15 at 13:34

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

With zsh (using the glob qualifier D):

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

To include non-hidden files in hidden directories:

setopt extendedglob
print -rl ./**/*~^*/.*(D)

Simple command to find hidden and non hidden files and directory

$ ls -a 
  • 3
    This is not recursive, and it does not list only the hidden files. – terdon Jul 10 '14 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.