Sunday, October 24, 2010

Find out non-system users

alias lsusers='getent passwd | tr ":" " " | awk "\$3 >= $(grep UID_MIN /etc/login.defs | cut -d " " -f 2) { print \$1 }" | sort'
 
Above command to list non-system users. It should be portable though won't work on systems without the getent command.

1 comment:

Anonymous said...

Some improvements:
{ if command -v getent > /dev/null; then getent passwd; else cat /etc/passwd; fi; } | awk -F: "\$3 >= $(awk '$1 == "UID_MIN" { print $2 }' /etc/login.defs 2>/dev/null || echo 1000) && \$1 != \"nobody\" { print \$1 }" | LC_ALL=C sort