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?

1 Answer 1


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
    Commented Aug 29, 2019 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 Commented Aug 30, 2019 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. Commented Aug 30, 2019 at 3:44
  • Thank you, I simply forgot the special dot entry was part of the result.
    – Stphane
    Commented Aug 30, 2019 at 6:38

You must log in to answer this question.

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