Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a user-friendly command I can use to list users in a console on an Ubuntu system?

When I cat /etc/passwd I get a hard-to-read list of users. It would be nice to see an alphabetized list, with entries arranged into columns, and with group names in parentheses beside the group IDs.

share|improve this question
well, /etc/passwd is arranged into columns... if you want to see only a few colums, perhaps use cut. For alphabetized, there is sort. If you need the group names, play with join (which may actually be able to show only a subset of columns, btw). – njsg Feb 3 '13 at 13:15
up vote 22 down vote accepted

Good way for nice output of /etc/passwd file:

$ column -nts: /etc/passwd

Now you can sort it:

$ column -nts: /etc/passwd | sort

With groups names in last column (no parenthesis):

$ paste -d: /etc/passwd <(groups $(cut -d: -f1 /etc/passwd) | sed 's/.*: //') | column -nts: | sort
share|improve this answer
Thanks, these commands do what I want. To a newbie this is very daunting though... I suppose I'll have to learn how to create an alias for them. – M. Dudley Feb 3 '13 at 17:07
On Centos column didn't like the n option. column -ts: /etc/passwd worked fine. – user1014251 Nov 10 '15 at 13:19

If you have root access on the machine, you can do the following:

sudo grep -vE '^[^*!]+:[*!]:' /etc/shadow | sort | cut -d: -f1 | while read user; do id $user; done | column -ts' ,' | vi '+set nowrap' -

How it works

Become root to read the shadow file. You only require root privileges if you want to check if the user has a password set (human user), otherwise you can just cat /etc/passwd instead of sudo grep ...:


Only show users which have a password set:

grep -vE '^[^*!]+:[*!]:' /etc/shadow

Sort by username:


Discard all information except for the username:

cut -d: -f1

Iterate through the usernames and enrich it with group infomration:

while read user; do id $user; done

Format the input into columns:

column -ts' ,'

Use vi to view the result:

vi '+set nowrap' - 

If you don't have root access,

try something like this:

cut -d: -f1 /etc/passwd | sort | while read user; do id $user; done | sed 's/\(\()\|^\)[^(]*(\|)\)/ /g' | column -t

Its output is a bit different, but I leave it as an exercise to the reader to combine the two parts in this answer into something that fully fits the job. (Don't you just love sed?)

share|improve this answer
"I leave it as an exercise to the reader..." :) – Emanuel Berg Feb 3 '13 at 21:13

I thought this would be easy with join, but join requires the files to be sorted on the join field. So it required (?) a workaround with temporary files. The output is sorted on user, and displays user, group, and group ID.

uag () {
  cat /etc/group  | tr ":" " " | sort -k 3 -o $TEMP_GROUPS
  cat /etc/passwd | tr ":" " " | sort -k 4 -o $TEMP_USERS
  join -1 4 -2 3 -o 1.1,2.1,2.3 $TEMP_USERS $TEMP_GROUPS | sort

Translate a character into another with tr; sort according to a key field with -k, output to file with -o; join with regard to fields in the first (-1) and second (-2) file, output certain fields in the first file (-o 1.1) as well as the second (,2.1,2.3).

share|improve this answer
note that /tmp would be better, because FHS states that /var/tmp won't be wiped on reboots, which we don't really need. – strugee Sep 9 '13 at 3:25

In Ubuntu it can be as follows:

seven fields from /etc/passwd stored in $f1,f2...,$f7

while IFS=: read -r f1 f2 f3 f4 f5 f6 f7
 echo "User $f1 use $f7 shell and stores files in $f6 directory."
done < /etc/passwd
share|improve this answer

Something that I do and it works for my purposes is

ls /home

Granted, that doesn't really give you a list of users rather a list of user's home directories and past user's directories but any command you want to do on a user that doesn't exist terminal will tell you and could be a hint to remove the home file that doesn't have a user or move it!

share|improve this answer

Your Answer


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.