views:

60

answers:

2

Hi, Can some one please tell me how can I find the following.

List from /etc/passwd the UID and the user having the highest UID.

+3  A: 
cat /etc/passwd | awk -F: '{print $3,$1}' | sort -n | tail -n 1
localhost
you can also substitute `awk` with `cut` : `cat /etc/passwd | cut -d":" -f3 | sort -n | tail -n 1`
nsr81
@nsr: That won't print the user name though.
sepp2k
+1  A: 

/etc/passwd contains user information separated by colons. The user id is in the third column.

The sort command line tool can be used to sort the lines of a file. It has options, to choose which separator the columns are separated by, which column to sort by and whether to sort numerically or alphabetically.

So you can use sort to sort /etc/passwd by user id and then use tail to get the last line from that, which will contain the user with highest id.

sepp2k