Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Actually that only gets users (actually uids/gids) from 500-999; its perfectly normal to have much higher numbers and (as mentioned above), some systems start the non-priv uids at 1000 ...
While I am dazzled by the display of programming expertise evidenced in all the replies to this post, I cannot for the life of me understand what is wrong with just using the users command. It gives a non-cluttered view of the actual people (not system, etc.) who are logged on to the box. Sometimes things just get a little too complicated to be of any use. Just MHO.
The "users" command only lists those who are logged in. Not all users.
If you want to know all the local users, look in the /etc/passwd file.
HOWEVER, that will not necessarily list all the users. IF you are using NIS then you must also use ypcat passwd.
And even then, that isn't necessarily all the users...
If you are using kerberos, you won't know. The users are authenticated via remote connection to the key distribution server, and you normally will not be able to list those users.
If you are using LDAP, you have yet another place to look... ldapsearch...
How would you utilize trap to display a list of logged on users each time you log out?
Depends on the definition of logout...
You can use "trap who exit" in the ~/.bash_login. Then, when that login shell exits you will get the output of "who" (which lists the current logged in users). If you don't want to know how many times they are logged in ... then you can do:
Code:
...
# luu is "list unique users"
function luu {
who | awk '{print $1}' | sort -u
}
trap luu exit
...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.