It is a good idea to occasionally check your Unix system for orphaned files. Normally you do so by using find with the -nouser and -nogroup filters. You could do two separate searches, one for -nouser, and then one for -nogroup, but typically the two are combined in one find command. Now here is the gotcha:
find / -nouser -nogroup -print
If you search find "-nouser -nogroup" on Google you likely find some examples like the one above. The problem with it is that there is an implied and when two or more filters are used as in the example. It is the same as doing the following (explicitly):
or:
The examples above will only 'find' files that belong to 'nouser' and 'nogroup.' If a file matches -nouser, but not -nogroup, find will not display it. If a file exists that matches -nogroup, but not -nouser, it will not display. Find will only return results that meet both criteria. In order to find all orphaned files, you want to do an or:
Now go have some fun tracking down those orphaned files!
find / -nouser -a -nogroup -print
or:
find / -nouser -and -nogroup -print
The examples above will only 'find' files that belong to 'nouser' and 'nogroup.' If a file matches -nouser, but not -nogroup, find will not display it. If a file exists that matches -nogroup, but not -nouser, it will not display. Find will only return results that meet both criteria. In order to find all orphaned files, you want to do an or:
find / -nouser -o -nogroup -print
Now go have some fun tracking down those orphaned files!
No comments:
Post a Comment