LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-02-2010, 08:53 AM   #1
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Rep: Reputation: 77
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?
 
Old 02-02-2010, 08:59 AM   #2
SethsdadtheLinuxer
Member
 
Registered: Jun 2007
Posts: 152

Rep: Reputation: 37
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.
 
Old 02-02-2010, 09:27 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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
 
Old 02-02-2010, 09:57 AM   #4
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
Thanks for the awesome info all!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ls to view directories only mikemrh9 Linux - Newbie 26 07-08-2015 01:27 PM
how to view only directories with ls LinuxLover General 5 09-15-2006 11:55 AM
Apache Root/Home Directory and setting up FTP for home directories? Mankind75 Linux - Newbie 6 07-23-2006 02:37 PM
How to view those .directories thort Linux - Newbie 3 02-12-2006 12:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration