Primal Habits
It is currently Sun Mar 26, 2017 12:51 pm


Feed

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Thu Aug 18, 2011 11:52 pm 
Offline
User avatar

Joined: Sun Apr 25, 2010 1:02 pm
Posts: 115



How to list all your Users in Linux

I will try to keep this simple.

We all should know the user list reside in /etc/passwd, so we can view the registered user by looking into the file /etc/passwd .
Attention!! It also contains many other machine / fields trusted accounts & built in accounts.

So now we can make a command..

We can start by
1. cat /etc/passwd

2. We all should know that by default all the users created will have their home directories most likely in /home directory.
We can modify our command a bit by using grep.
Now it should be
cat /etc/passwd | grep "/home"

3. The result should be all the user accounts which have their home share in /home.
But the output we actually need is the list of users & nothing else.

4. Now we can modify our command again
cat /etc/passwd | grep "/home" |cut -d: -f1
What we have done is we have piped the output of previous command to another variable "cut"
What has been done here is we have added
cut -d: -f1
-d: means delimiter :
-f1 means display first field of line i.e. username.

So the final command should be...
cat /etc/passwd |grep "/home" |cut -d: -f1

This works for all your users that have their home share in /home.
If you have defined their home share to be in some other location.
You should modify the above command.


*Clue - In the previous case we started grep "/home" ...
This time we should use grep "/bin/bash" or whatever valid shell you are using*

Now your command should be..
cat /etc/passwd |grep "/bin/bash" |cut -d: f1

Keep in mind that this can also result some built in user accounts.
Avoiding this we should now pipe the output to different / other variable.

_________________
Check Out RouterHead8080 T.V.



Share on FacebookShare on TwitterShare on TuentiShare on SonicoShare on FriendFeedShare on OrkutShare on DiggShare on MySpaceShare on DeliciousShare on Technorati
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 7 hours [ DST ]


Related topics
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. List of IF STATEMENTS PHPBB3

RouterHead8080

0

17238

Mon Feb 18, 2013 2:59 pm

RouterHead8080 View the latest post

There are no new unread posts for this topic. How do I install RKHunter on Linux ?

RouterHead8080

0

1196

Fri Aug 19, 2011 12:29 am

RouterHead8080 View the latest post

There are no new unread posts for this topic. How to tell which version of Linux CentOS you are using.

RouterHead8080

0

1366

Fri Aug 19, 2011 12:40 am

RouterHead8080 View the latest post

There are no new unread posts for this topic. How to Catch Spammer WHM Centos5 Linux

RouterHead8080

0

1904

Thu Jul 28, 2011 8:01 pm

RouterHead8080 View the latest post

There are no new unread posts for this topic. How to install ClamAV on Linux / Centos 5.5

RouterHead8080

0

3274

Fri Aug 19, 2011 9:13 am

RouterHead8080 View the latest post

 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron

Affiliates    Terms of use    Privacy policy   

Primal Habits, a Sceptersoft Company
Copyright © 2010 - 2017 Sceptersoft LLC. All rights reserved.