Posted: . At: 11:25 AM. This was 6 years ago. Post ID: 11964
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.



Sponsored



How to print information about Linux users with the shell.


To get information about Linux users with the shell, give these examples a go.

Get a listing of all /home folders on Linux.

jason@Yog-Sothoth:~/Documents$ sudo gawk -F: '{ print $6 }' /etc/passwd | grep /home
/home/syslog
/home/jason
/home/justin
/home/daniel

Count the number of users on your Linux system.

jason@Yog-Sothoth:~/Documents$ sudo gawk -F: '{ print $1 }' /etc/passwd | wc -l
49

Get information about a certain user.

jason@Yog-Sothoth:~/Documents$ finger -lmps mathis
Login: mathis          			Name: Mathis Miles
Directory: /home/mathis              	Shell: /bin/bash
Office: 101
Never logged in.
No mail.

List the Linux users that are actually logged in at this moment.

jason@Yog-Sothoth:~/Documents$ users
jason

List all groups your Linux user is a member of.

jason@Yog-Sothoth:~/Documents$ id -Gn
jason adm cdrom sudo dip plugdev lpadmin sambashare

Get the user`s string from the /etc/passwd file with this command.

jason@Yog-Sothoth:~/Documents$ sudo getent passwd mathis
[sudo] password for jason: 
mathis:x:1002:1002:Mathis Miles,101,,:/home/mathis:/bin/bash

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.