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.

2 Answers 2

3

Use path instead of iname:

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

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .