No entries in /etc/passwd
I know that /home contains all the home directorys for all users. I also know that /etc/passwd current list of all valid users. However, I am trying to figure out a command that lists users that do not have entries within the /etc/passwd.
I know that using the following command: Code:
$ awk -F":" '{ print $1 }' /etc/passwd |
First of all - not *all* users have a home under /home ... most system
accounts don't. The easiest way to determine whether someone who has a home under /home, but no actual account anymore is to just look at the long output of ls. This is true on most variants (with default installations) of Linux/Unix that I've come across: if the 3rd field is numeric only, the user isn't in /etc/passwd anymore ... Cheers, Tink |
Okay, I'm lost. lol
|
Code:
ls -l /home | awk '$3 !~ /a-zA-Z/' |
Thank you, trying that. :)
This is what I see when I enter in the command that you gave me: Code:
$ ls -l /home | awk '$3 !~ /a-zA-Z/' | more |
To elaborate: in Unix, the file-ownership is determined by
numeric user and group ids (the third field in /etc/passwd, and /etc/group). Linux commands like ls will be "friendly" and map the numbers to names by default. If someone doesn't exist in password any more, you'll see a numeric only ID in the output of ls. |
So how would I go about having it just list the ones with no entries into /etc/passwd, instead of all? I hope that makes sense.
|
In your example above they all do have a numeric owner.
root or directory. Whether that's desired or not I cannot tell ;} |
Maybe I didn't explain what I wanted correctly in the first place? Let me see if I can explain a little better. (puts on thinking cap)
I guess this is what I am trying to figure out for a command to do. I am trying to figure out a command that list users who have home directories, but do not have entry in /etc/passwd. Maybe I did word it wrong the first time? |
If it's a number instead of a user, their account has been deleted.
If it's not in /etc/passwd, it's not a user. |
You could try this:
Code:
for dir in $(ls -d /home/*) Code:
if ! grep "$dir' /etc/passwd # if no user has this directory set as home Rob |
I don't know, I am so confused now. lol All I am trying to do is get a list of users who have home directories, but do not have entry in /etc/passwd. But I am not sure if I am wording it correctly as to what I am after.
|
OK - I added a directory called "george" to my /home (no such user - there's also no user called lost+found!):
Code:
rob:~$ ls -d /home/* |
Quote:
braces around my awk regex. It should have said: Code:
ls -l /home | awk '$3 !~ /[a-zA-Z]/' setting (in your mind) a user name to be equivalent to the name of the users home directory. While this commonly is the case, it's not always like that, and it's certainly not required. When you say you want to find a directory whose owner isn't in /etc/passwd looking at the names is technically speaking not correct. However, it would appear that in your practical example output above there's a whole lot of directories under home owned by two users whose names aren't reflected in the directories names, namely a user directory and root. If the directories above weren't owned by anyone I'd expect to see something like this in ls' output. Code:
ls -l /home | awk '$3 !~ /[a-zA-Z]/' | more Cheers, Tink |
I give up. But thanks for your guy's help! I appreciate it.
|
All times are GMT -5. The time now is 03:26 PM. |