Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
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.
can anyone tell a command to list all the users of a system...........................
to be specific, not the users that are currently logged in, i want a command that lists all the users which have been created(including that ones created by softwares or OS itself) and i do know that it can be found by /etc/passwd...but i want a command.............
So how do you see list of users.....
Any guesses..
(I'll tell you & make it short & simple...)
As we all know the user list reside in /etc/passwd, so we can view the registered user by looking up at this file.
But now the fuss is that it also contains many other fields & machine trust accounts & inbuilt accounts.
So now we'll make a command of our own..
We'll start by
1.cat /etc/passwd
2.As we all know that by default all the users created will have their home directories in /home share
so we'll modify our command a bit by using grep.
Now it'll be
cat /etc/passwd | grep "/home"
3. Now we'll get all the user accounts which have their home share in /home.
But the only output we need is the list of users & nothing else.
4. So we'll modify our command again
cat /etc/passwd | grep "/home" |cut -d: -f1
Now what we have done is that we have piped the output of previous command to another variable "cut"
What we have done here is we have added
cut -d: -f1
-d: means delimite :
-f1 means display first field of line i.e. username.
So final command is
Cat /etc/passwd |grep "/home" |cut -d: -f1
This works until all your users have their home share in /home. If you have defined their home share to some other destination. Modify the above command.
(Hint : In previous case we started grep "/home" , this time we'll use grep "/bin/bash" or whtever valid shell you are using)
Now command will be like..
Cat /etc/passwd |grep "/bin/bash" |cut -d: f1
But this will also result some inbuilt user account.
To avoid that.. we'll now pipe the output to another variable… as we know that UID starts from 500 & above..
So our new command would be:
This command is not going to help you if you are using SSO or even an ldap/nis authentication. because centralised users will not show up at /etc/passwd file.
Originally posted by Rinish This command is not going to help you if you are using SSO or even an ldap/nis authentication. because centralised users will not show up at /etc/passwd file.
/ Rinish (rinishriju)
I am taking the case we are using /etc/passwd.
In case of LDAP/NIS... this procedure is not going to work.
Last edited by amitsharma_26; 10-06-2005 at 12:51 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.