LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What is the command to list users? (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-command-to-list-users-367164/)

toothpick 04-18-2010 12:00 PM

Alternative.....
 
How about just "less /etc/passwd"?

anthalamus 10-13-2010 10:14 AM

if someone's looking at this thread for an answer to a good way to reverse look up user per UID, I like:
Code:

getent passwd | awk -F: '$3=='$SOME_USER_ID'{print $1}'
more reliable than using /etc/passwd, especially when user dirs are mounted from elsewhere
hope it helps someone

pburwell 10-22-2013 12:00 PM

List Users in RHEL6.x
 
Quote:

Originally Posted by neo_in_matrix (Post 1871535)
There are useradd/userdel, but I could not find the command to list users. Plase help.

I know this an OLD question but RedHat STILL has not found an easy way to do this.
SO, make an executable file in /bin with this:

cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]" | grep "/home" | cut -d: -f1

I used nano and made getusers with 0777 permissions

chrism01 10-23-2013 05:28 AM

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 ...

Here's a 'std' anomaly
Code:

nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
:)

GNU/Linux 10-23-2013 07:13 AM

First look in /etc/login.defs which contains the minimum & max UID for (normal) users
Code:

$ grep "^UID_MIN" /etc/login.defs
$ grep "^UID_MAX" /etc/login.defs


OldSASguy 10-23-2013 09:10 AM

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.

jpollard 10-23-2013 03:16 PM

Mostly because it doesn't answer the question.

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 to list users depends on your environment.

OldSASguy 10-23-2013 03:22 PM

well, jollard, if you're gonna get picky!! You're right of course - there is a difference between "users" and "active users". My bad!

dchawk 02-12-2014 10:04 PM

How would you utilize trap to display a list of logged on users each time you log out?

jpollard 02-12-2014 10:43 PM

Quote:

Originally Posted by dchawk (Post 5116614)
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
...


shadow_cat 11-28-2017 07:52 AM

Easy Command
 
Compgen - u

MadeInGermany 11-29-2017 01:07 AM

Code:

getent passwd
lists the effective passwd lines (including name services, according to the passwd line in /etc/nsswitch.conf).
Cut the login-ID (field#1) with
Code:

getent passwd | cut -d: -f1
or
Code:

getent passwd | awk -F: '{print $1}'
In the latter you can add a filter, like
Code:

getent passwd | awk -F: '$3>=500 {print $1}'

giis 11-29-2017 06:09 AM

Seems like this is very old post. Mods, please mark it as solved/closed.


All times are GMT -5. The time now is 06:07 AM.