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
tee could be avoided if you do not need to see the output, and
-ls option should be used only if required).
To list the hidden files and directories in the current directory, including
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
zsh (using the glob qualifier
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