Linux - How to list all users

Tadeusz Majkowski picture Tadeusz Majkowski · Nov 28, 2013 · Viewed 52.7k times · Source

How to write a script for linux which list all users from /etc/passwd and their UID

User1 uid=0001
User2 uid=0002
...

the script should use: grep, cut, id, for

Answer

Kent picture Kent · Nov 28, 2013
awk -F: '$0=$1 " uid="$3' /etc/passwd

awk is easier in this case.

-F defines field separator as :

so you want is 1st and 3rd colums. so build the $0 to provide your output format.

this is very basic usage of powerful awk. you may want to read some tutorials if you faced this kind of problem often.

This time you got fish, if I were you, I am gonna do some research on how to fishing.