LinuxQuestions.org

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

neo_in_matrix 09-26-2005 10:27 AM

What is the command to list users?
 
There are useradd/userdel, but I could not find the command to list users. Plase help.

Andrew Benton 09-26-2005 10:44 AM

cat /etc/passwd

visaris 09-26-2005 10:44 AM

I'm not sure about a command but you could look in the /etc/passwd file.

"cat /etc/passwd"
should (on most systems) give you a list of all the users on the system. Keep in mind that some special users may be listed here along with the regular ones.

amitsharma_26 09-26-2005 10:02 PM

Try this...
 
cat /etc/passwd |grep 500*


It will list all lines from /etc/passwd which corresponds to USERs on your box. So from there you can check out the characters before first ":" sign will be the login name for your all users.

Reason---> It will list all the users with UID 500 or above... & the result would be the list of your normal users.

Start using grep... & be more creative. It will help.


Do feedback.

homey 09-26-2005 10:51 PM

I'd be more inclined to look for users with a home directory....
Code:

cat /etc/passwd | grep /home | cut -d: -f1

Dark_Helmet 09-26-2005 11:28 PM

Quote:

Originally posted by amitsharma_26
cat /etc/passwd |grep 500*
...
It will list all the users with UID 500 or above.

That's not entirely true. That grep pattern will match 50, 500-509, 5000-5099, etc. It won't list users with ID's of 510-4999. Also, different distributions use different starting points for beginning UIDs. 500 is pretty common, but I've seen some that start at 1000. A slightly improved version of the command above would be:
Code:

cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]"
That's not perfect, but it would list UIDs of 500-999. And it would prevent any matching of numbers in comment or GID fields.

Then it could be combined with homey's suggestion for something like this:
Code:

cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]" | grep "/home" | cut -d: -f1
But now it's getting to be a pretty long command, and not the easiest to remember. Alias time :)

Vgui 09-27-2005 01:49 AM

Also, as a slightly related aside, the "who" command will tell you who is currently logged onto the system.

harisund 09-27-2005 03:14 AM

who & finger too !

amitsharma_26 09-27-2005 10:54 AM

Quote:

Originally posted by Vgui
Also, as a slightly related aside, the "who" command will tell you who is currently logged onto the system.
That will be done by

users

also.

But it wont list any samba users logged in.

Tomas Tyser 02-17-2009 07:29 AM

ls /home

john test 02-20-2009 11:19 AM

Might try:
Code:

net rap user
Seems to give a pretty comprehensive list

enthus 02-26-2009 08:10 PM

Quote:

Originally Posted by Tomas Tyser (Post 3446785)
ls /home

genius!!!

my command:

cat /etc/passwd | gawk 'FS=":" {print $1}'

Tinkster 02-26-2009 08:38 PM

Quote:

Originally Posted by Dark_Helmet (Post 1872523)
Then it could be combined with homey's suggestion for something like this:
Code:

cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]" | grep "/home" | cut -d: -f1
But now it's getting to be a pretty long command, and not the easiest to remember. Alias time :)

Code:

awk -F: '$6 ~ /\/home/ && $3 >= 500 {print $1}' /etc/passwd

And a note to most people in this thread:

If you find yourself using 'cat' with only one parameter you're
not making good/sensible use of it 99.9% of the time.

palisetty_suman 02-27-2009 12:59 AM

Hi
 
Hi,

I guess the command

cat /etc/passwd

is correct and simpler to use. All The Best.

anirudhm 11-04-2009 03:02 AM

My Command is :
 
gawk -F: '{ print $1 }' /etc/passwd


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