Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the highest user ID in Mac OS X

Tags:

shell

macos

I'm writing a script to add new users to an OS X system on the command line. I know I can list all users on a system with their user IDs using:

dscl . -list /Users UniqueID

which gives something like:

xxxxxxx                         937
xxxxxxxx                        939
xxxxx                           940
xxxxxx                          941

How can I retrieve the greatest user ID from this output to store in a variable?

like image 810
Jake Petroules Avatar asked Jan 27 '12 02:01

Jake Petroules


1 Answers

This will give you the line with the highest ID:

dscl . -list /Users UniqueID | sort -nr -k 2 | head -1
like image 146
Scott Hunter Avatar answered Oct 06 '22 11:10

Scott Hunter