LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   user id number (https://www.linuxquestions.org/questions/linux-newbie-8/user-id-number-946626/)

linuxandtsm 05-24-2012 08:21 AM

user id number
 
Hi all,

how to find what is the max id number that is been assigned to a user in linux ?
/etc/passwd file might have it but not sure how to find it if it has too many entries in it ?

and also what is the range of id's can be used in linux ?


Thanks in advance!

acid_kewpie 05-24-2012 08:34 AM

/etc/login.defs defines the max and min uids and gids. There is no formal way to find out the current max UID, as it's not an interesting thing to want to know. you can easily spit the output of "getent passwd" through cut and the likes though.


getent passwd | cut -d: -f4 | sort -n | tail -n1

whizje 05-24-2012 08:45 AM

Code:

awk -F":" 'END{ print "username: " $1 "\t\tuid:" $3 }' /etc/passwd
Assumed the last entry has the highest uid. Else you have to search the passwd file for the highest uid.

whizje 05-24-2012 08:49 AM

Quote:

getent passwd | cut -d: -f4 | sort -n | tail -n1
-f4 needs to be -f3

acid_kewpie 05-24-2012 08:51 AM

Quote:

Originally Posted by whizje (Post 4686398)
-f4 needs to be -f3

Doh yes, I tested that against an F5 BigIP appliance which makes all users uid 0 so I got confused!

linuxandtsm 05-24-2012 09:00 AM

Thanks everyone for quick and exact solution!!!


All times are GMT -5. The time now is 12:07 PM.