bash - Shell script to get list of defined users on Linux? -


i put together, sucks: (e.g. magic numbers in there, text parsing.. boo!)

awk -f: '{if($3 >= 1000 && $3 < 2**16-2) print $1}' /etc/passwd 

what's proper way this?

some unix systems don't use /etc/passwd, or have users not specified there. should use getent passwd instead of reading /etc/passwd.

my system has users disabled , can lo longer login login command set /bin/false or /usr/sbin/nologin. want exclude them well.

here works me including arheops awk command , ansgar's code min , max login.defs:

getent passwd | \ grep -ve '(nologin|false)$' | \ awk -f: -v min=`awk '/^uid_min/ {print $2}' /etc/login.defs` \ -v max=`awk '/^uid_max/ {print $2}' /etc/login.defs` \ '{if(($3 >= min)&&($3 <= max)) print $1}' | \ sort -u 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -