If you want to list all users in Linux, this is the article for you. It should be a fairly short article, but it should tell you how to list all users. So, there’s that. By that, I mean it’ll probably do what it says on the tin, namely telling you how to list all your users.
You may want to check the list of users from time to time. Applications may add users, you may have added users, malicious software or people may have added users, etc… There are other reasons to list all users, but you get the idea.
This is a beginner-level exercise, so you shouldn’t have any difficulty with it. It should also be reasonably short, which is nice! If you find any mistakes or have any questions, scroll down and leave a comment. You can also ask on the lovely Linux.org forums.
Without further ado…
List All Users:
Once again, we start with opening the terminal. To do this, you just press
Got it open? Good, ’cause it’s a pretty easy operation. The file you’re looking for is ‘/etc/passwd’, which is a plain text file that’s in conjunction with the /etc/shadow file. Like most text files, it’s easy enough to work with them in the terminal.
So, to show the content of the file (and see the list of users):
1 | cat /etc/passwd |
If you want to show fewer results at a time, you can just use:
1 | less /etc/passwd |
If you want, you can ‘grep’ a specific user. Just pipe the output to grep and you’re good to go. It looks like this:
1 | cat /etc/passwd | grep root |
If you want to use that format AND have numbered lines, one way of finding out how many users there are, then just use:
1 | less -N /etc/passwd |
Though you could just as easily have used this to get the number:
1 | cat /etc/passwd | wc -l |
If you want to list just the users, you can use ‘awk’ and pick the first column like this:
1 | awk -F: '{ print $1}' /etc/passwd |
And that’s about it, really. You’ve now listed all the users – and counted ’em!
Closure:
That’s it! That’s all there is to it, and you’ve learned a little bit more – this time how to list users in Linux. I told you that it’d be pretty painless and easy. Plus, this is another article for the books – and this one authored early enough to give me some time to keep scheduling them ahead of time.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.