5

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.

3

Use path instead of iname:

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

You could also do the opposite and match them. It allows find to prune, which prevents descending into the matching directories it can speed up your search considerably.

find -path '*/.*' -prune -o -print

Explicit use of -print on the right side only prints the non-matching objects, in this case, visible files and folders.

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.