This command prints files/directories in the working directory having a basename starting with a period (a.k.a. hidden entries), non recursively.

find . -maxdepth 1 -name '.*'

To print everything but those hidden entries I expected the following command to work … but nothing gets printed.

find . -maxdepth 1 -name '.*' -prune -o -print

I ran those commands in my home directory where some non hidden entries exist like Documents, Downloads directories, some miscellaneous files etc which I expected to be printed.

Can someone explain me why?


The -prune predicate prunes directories - in this case, -name will match the starting directory . and hence prune the whole tree.

What you want to do is simply negate the -name match:

find . -maxdepth 1 ! -name '.*'


find . -maxdepth 1 -not -name '.*'
  • So find matches current special entry ".", but that dir name actually matches -name .* and as a result gets pruned, right? – Stphane Aug 29 at 23:53
  • @Stphane yes that's right... I think... I'm sure a more experienced contributor will correct me if that's not the case – steeldriver Aug 30 at 0:06
  • 1
    Yes, that’s right; you can verify this by running find . -maxdepth 1 -name '.*' -prune -print (to prune and print) or even find . -name '.*' -prune -print. – Stephen Kitt Aug 30 at 3:44
  • Thank you, I simply forgot the special dot entry was part of the result. – Stphane Aug 30 at 6:38

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.