Sunday, May 5, 2024
23
rated 0 times [  23] [ 0]  / answers: 1 / hits: 29285  / 2 Years ago, tue, april 5, 2022, 5:49:14

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.


More From » command-line

 Answers
4

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).


[#32644] Thursday, April 7, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
horicgly

Total Points: 36
Total Questions: 126
Total Answers: 104

Location: Iceland
Member since Thu, Dec 1, 2022
1 Year ago
;