On a Unix/Linux system, you can locate files or directories that don't belong to a valid user account or group on the system with the command
find
and the -nouser
or -nogroup
option.
-nogroup No group corresponds to file's numeric group ID. -nouser No user corresponds to file's numeric user ID.
find . -nouser
# find . -nouser ./temp ./temp/bounced.txt ./temp/._Oct14(10-2).pdf ./temp/._Oct14.doc
The above example shows that the directory temp
and three
files within it don't have a valid owner. Checking them with the ls
command, I see a long sequence of digits listed for the ower and
group instead of an account listed in /etc/passwd
or
/etc/group
.
# ls -ld temp drwxr-xr-x. 2 723184451 1286109195 74 Feb 13 17:09 temp # ls -al temp total 60 drwxr-xr-x. 2 723184451 1286109195 74 Feb 13 17:09 . drwx------. 8 jasmith1 jasmith1 4096 Apr 10 22:26 .. -rw-r--r--. 1 723184451 1286109195 45333 Oct 6 2014 bounced.txt -rw-r--r--. 1 723184451 1286109195 192 Oct 6 2014 ._Oct14(10-2).pdf -rw-r--r--. 1 723184451 1286109195 192 Oct 6 2014 ._Oct14.doc
Files or directories with no group listed in /etc/group
corresponding to the numeric group id for the file or directory
can be found with find . -nogroup
to search in and beneath
the current directory or find / -nogroup
to search starting
at the root directory.
# find . -nogroup ./temp ./temp/bounced.txt ./temp/._Oct14(10-2).pdf ./temp/._Oct14.doc ./mail ./mail/.imap ./mail/.imap/INBOX ./mail/.imap/INBOX/dovecot.index.cache ./mail/.imap/INBOX/dovecot.index ./mail/.imap/INBOX/dovecot.index.log # ls -ld mail drwx------. 3 jasmith1 508 18 Sep 29 2014 mail # ls -al mail/.imap/INBOX total 20 drwx------. 2 jasmith1 508 76 Sep 29 2014 . drwx------. 3 jasmith1 508 18 Sep 29 2014 .. -rw-------. 1 jasmith1 508 144 Sep 29 2014 dovecot.index -rw-------. 1 jasmith1 508 10272 Sep 29 2014 dovecot.index.cache -rw-------. 1 jasmith1 508 96 Sep 29 2014 dovecot.index.log
You can use the -o
option for "or" to find files and
directories that either don't have a user account associated with the numeric
user id or don't have a group associated with the numeric group id. E.g.,
find . -nogroup -o -nouser
.
If you delete an account or group from the system, files or directories
that remain that had that owner or group will then be displayed with the
user id and group id associated with the account or group that was deleted
when you use the ls
command.