AIX/Linux - Orphaned files and directories

Posted on 2013-09-27
Medium Priority
Last Modified: 2013-10-07
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.
Question by:AIX25
  • 2
  • 2
LVL 68

Assisted Solution

woolmilkporc earned 1000 total points
ID: 39528804
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
LVL 40

Accepted Solution

omarfarid earned 1000 total points
ID: 39528940
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.
LVL 68

Expert Comment

ID: 39528982
Thanks for the hint, omarfarid!

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


Author Comment

ID: 39552635
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?
LVL 40

Expert Comment

ID: 39554464
Thank you woolmilkporc.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question