LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-24-2012, 09:21 AM   #1
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Rep: Reputation: Disabled
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!
 
Old 05-24-2012, 09:34 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
/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

Last edited by acid_kewpie; 05-24-2012 at 09:35 AM.
 
Old 05-24-2012, 09:45 AM   #3
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 594

Rep: Reputation: 141Reputation: 141
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.
 
1 members found this post helpful.
Old 05-24-2012, 09:49 AM   #4
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 594

Rep: Reputation: 141Reputation: 141
Quote:
getent passwd | cut -d: -f4 | sort -n | tail -n1
-f4 needs to be -f3
 
1 members found this post helpful.
Old 05-24-2012, 09:51 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by whizje View Post
-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!
 
1 members found this post helpful.
Old 05-24-2012, 10:00 AM   #6
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Thanks everyone for quick and exact solution!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What does it mean when the user is a number? pgflrob Linux - Newbie 4 03-11-2012 11:09 AM
New user - number of posts before url Jeebizz LQ Suggestions & Feedback 21 09-21-2011 12:22 PM
Identify and explain the major number, minor number, and revision number in Linux... turbomen Linux - Newbie 1 11-16-2010 03:48 AM
Number of current sessions for user neel_learning_linux Linux - Newbie 5 05-13-2009 04:14 PM
user shows up as a number in ps aux chibi Linux - General 3 05-04-2005 09:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration