8

I need to search for files that has no user OR no group.

find / -nouser -o -nogroup

I think this is OK. But, I don't want to search NFS shares. How can I exclude the NFS shares in the find command?

  • 2
    Try find / -fstype ext4 -nouser -o -nogroup Substitute ext3, etc. if you're not using ext4 – doneal24 Feb 6 '13 at 15:18
  • 1
    please post this as answer – gasko peter Feb 6 '13 at 15:40
  • @DougO'Neal you should post that as an answer. – Tim Kennedy Feb 6 '13 at 15:55
  • 1
    @DougO'Neal, that wouldn't stop find from descending into nfs FS, just not to print the files it would find there. – Stéphane Chazelas Feb 6 '13 at 22:58
  • For using -exec with something like du combining -fstype and -xdev (aka -mount) seems necessary – Gert van den Berg Jan 19 '17 at 9:00
6

With GNU find, you can use the -fstype predicate:

find / -fstype nfs -prune -o \( -nouser -o -nogroup \) -print

Having said that, hymie's approach probably makes more sense: white-list what FS you want to search rather than black-listing those that you don't want to search.

If you want to only include jfs2 file systems (assuming / is on jfs2), then, you need to write it:

find / ! -fstype jfs2 -prune -o \( -nouser -o -nogroup \) -print

Don't write it:

find / -fstype jfs2 \( -nouser -o -nogroup \) -print

As while that would stop find from printing files in non-jfs2 filesystem, that would not stop it from crawling those non-jfs2 filesystems (which you need -prune for).

Note that -a (AND which is implicit if omitted) has precedence over -o (OR), so you need to watch whether parenthesis are needed or not.

The above correct command is short for:

find / \( \( ! -fstype jfs2 \) -a -prune \) -o \
  \( \( -nouser -o -nogroup \) -a -print \)
8

The closest you will probably get is to use -xdev , which means "Don't descend directories on other filesystems." Then you'll need to specify which filesystems you do want to search.

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.