How to recursively list only hidden files from a terminal

Solution 1:

To recursively list only hidden files from a terminal, you can use the tool find with the -type f option:

find ~ -type f -name '.*'

This will find all files in the user's home directory for which the basename starts with a dot, i.e., a hidden file or folder. Remove -type f to list both hidden files and folders, or specify type d to list only hidden directories. Specify any other directory by replacing ~ with a valid pathname. Specify . to list hidden files in the current working directory and below.

Solution 2:

It may be hard to match every corner-case:

find \( -path './.*' -type d -empty -printf %P/\\n \) -o -type f -path './.*' -printf %P\\n