Ubuntu – How to filter out hidden files and directories in ‘find’

command linefindhidden-files

I would like to list all the non-hidden files and directories in my path.

This means that files beginning with . should be excluded from the result, along with files whose path contains a hidden directory:

foo/bar/.bazz.rc # Exclude
foo/.bar/bazz.rc # Exclude

How do I do that? I've tried:

find -maxdepth 2 -not -iname "*/.*"

But I still have hidden files in my results.

Best Answer

Use path instead of iname:

find -not -path '*/.*'
  • * - matches any string.
  • / - directory separator.