AIX/Linux - Orphaned files and directories

I have directories that have thousands of orphaned directories and files. The UID or GID shows up. I need a script that will scan a specific directory and output a file that will provide the list of all the directories and files under that specific directory that are orphaned. Please help.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use find:

find  /directory -nouser -o nogroup

This will display all files/directories owned by a user which is not  in /etc/passwd or a group which is not in /etc/group (or both).

If you want to add an action statement like -print or -ls enclose the search criteria in escaped parentheses:

find  /directory \( -nouser -o nogroup \) -ls
I think there is a typo

find  /directory \( -nouser -o -nogroup \) -ls

Why you have such problem? is it that you delete users and groups for users who left?

May be you should run find command before deleting these users or groups to identify files or directories owned by them.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Thanks for the hint, omarfarid!

You're right, it' s "-nogroup", of course.

AIX25Author Commented:
Yes, you are right..we should run the find first before deleting the user. Unfortunately, I now have to go back and clean up the mess.

woolmilkporc and omarfarid, not sure how to handle the points on this. woolmilkporc answered it correctly but with a typo...and omarfarid fixed the typo. Any help on the point allocation?
Thank you woolmilkporc.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.