LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   View Orphan Home Directories (https://www.linuxquestions.org/questions/linux-general-1/view-orphan-home-directories-786436/)

carlosinfl 02-02-2010 08:53 AM

View Orphan Home Directories
 
I realized my script for deleting users was not working properly. For some reason it did delete the user account from the system but did not use the 'userdel -r' command. I think I may have left some home directories in the system that are from old deleted accounts. Is there a command or way I can see what directories under /home are not tied to accounts that are in /etc/passwd?

SethsdadtheLinuxer 02-02-2010 08:59 AM

here's a "base" way to do it
grep home /etc/passwd > file1
ls -b /home > file2
diff -y file1 file2

I'm sure you could clean this up by replacing the grep with an awk or sed command.

catkin 02-02-2010 09:27 AM

Code:

#!/bin/bash
for dir in /home/*
do
    grep -q ":$dir:" /etc/passwd && echo $dir is a home directory || echo $dir is not a home directory
done


carlosinfl 02-02-2010 09:57 AM

Thanks for the awesome info all!


All times are GMT -5. The time now is 04:17 PM.