# Script or Command to get all username



## albsallu (Sep 11, 2009)

I am not too good with unix. I need a script that will give me a result of all username, Display name, and password in a text file.

Thanks


----------



## ale (Sep 11, 2009)

You can try `$ cat /etc/passwd | cut -d ":" -f 1`


----------



## albsallu (Sep 11, 2009)

What does it do?


----------



## albsallu (Sep 11, 2009)

It just give the username and not the display name and the password. I need something that could give me username together with the display name and/or the password


----------



## ale (Sep 11, 2009)

Uh, I didn't read the complete message.
That will give you only the usernames.
You can get the complete name using -f 5.
And about the password...


----------



## Oxyd (Sep 11, 2009)

You can't get the password easily.  The passwords are stored in an encrypted form in the root-readable-only file /etc/master.passwd, encrypted with crypt(3).


----------



## phoenix (Sep 11, 2009)

awk comes in handy for parsing text files that have a unique field separator.  For /etc/passwd and /etc/master.passwd, the colon ) is the field separator.  So all you need to do is figure out which field(s) to print, and tell awk to print them:

```
# cat /etc/master.passwd | awk -F":" '{ printf "%s %s %s\n",$1,$5,$2 }'
```
That will print field 1 (username), field 5 (full name), and field 2 (password), as they are stored in /etc/master.passwd.

To make it look nicer, you can add labels:

```
# cat /etc/master.passwd | awk -F":" '{ printf "username: %s  name: %s  password: %s\n",$1,$5,$2 }'
```


----------



## albsallu (Sep 11, 2009)

Thanks Phoenix. I got what I was looking for


----------

