List Only Usernames



dandwdad

New Member
Joined
May 26, 2020
Messages
7
Reaction score
7
Credits
57
My quickest way is
awk -F ':" '{print $1}' /etc/passwd

if you want to sort it by name add | sort -k 1, so
awk -F ':' '{print $1}' /etc/passwd | sort -k 1

or even reverse search
awk -F ':' '{print $1}' /etc/passwd | sort -r -k 1.

Hope that helps!
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,317
Reaction score
1,867
Credits
8,257
My quickest way is
awk -F ':" '{print $1}' /etc/passwd

if you want to sort it by name add | sort -k 1, so
awk -F ':' '{print $1}' /etc/passwd | sort -k 1

or even reverse search
awk -F ':' '{print $1}' /etc/passwd | sort -r -k 1.

Hope that helps!
Jinx!
I was just about to post pretty much exactly the same solution!
You beat me to it by a few seconds!
 

dandwdad

New Member
Joined
May 26, 2020
Messages
7
Reaction score
7
Credits
57
My quickest way is
awk -F ':" '{print $1}' /etc/passwd

if you want to sort it by name add | sort -k 1, so
awk -F ':' '{print $1}' /etc/passwd | sort -k 1

or even reverse search
awk -F ':' '{print $1}' /etc/passwd | sort -r -k 1.

Hope that helps!


I did think of one more thing for people not used to Linux - USUALLY human users are higher than a specified userid (500, 1000, etc.) so you can sort by userid then look only at the last /highest userid users.

sort -t ':' -k 3 -n /etc/passwd | awk -F ':' '{print $1 " " $3}'
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online


Top