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 delimiter :
-f1 means display first field of line i.e. username.
So final command is
Cat /etc/passwd |grep "/home" |cut -d: -f1
=============================== OR ===========================
cat /etc/passwd |grep /bin/bash |grep [5-9][0-9][0-9] |cut -d: -f1
=============================== OR ===========================
alias userlist='cat /etc/passwd |grep "/bin/bash" |grep "[5-9][0-9][0-9]" |cut -d: -f1'
=============================== OR ===========================
awk -F":" '{ print "username: " $1 "\t\tuid:" $3 }' /etc/passwd
=============================== OR ===========================
awk -F":" '{ print "Linux_name: " $1 "\t\tFull_Name: " $5 }' /etc/passwd
Source : http://www.linuxquestions.org/linux/answers/Networking/How_to_list_all_your_USERs
No comments:
Post a Comment