Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I list all human users that I've created? I've tried cat /etc/passwd and it just lists a lot of stuff.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Human users have UIDs starting at 1000, so you can use that fact to filter out the non-humans:

cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1

This cuts the first (username) and third (UID) colon-delimited fields from /etc/passwd, then filters for the resulting lines which end with a colon and four digits, then cuts the first (username) field from that, leaving you with a list of users with UIDs between 1000 and 9999.

If you have more than nine thousand users on your system, this will fail - but it's necessary to restrict the result to 4-digit UIDs in order not to catch nobody (UID 65534).

share|improve this answer

This does pretty much what Zero's answer does, just in one command instead of three:

awk -F: '$3 >= 1000 && $1 != "nobody" {print $1}' /etc/passwd

And thanks to Karel in the comments, the nobody user is also filtered out.

share|improve this answer
    
@karel Yeah, maybe. Instead of filtering by UID, I'm filtering out that username explicitly. There may be a reason for having a legitimate user with a UID that high... Who knows ;) –  Oli Aug 7 '13 at 11:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.