Skip to content
Advertisement

Count total number of users in Linux (system users not included) [closed]

Screenshot of my users

i am trying to count total amount of users that i created in linux. I found out a script that works, I am using the method if uid is 1000+ then its someone that i created. however it was wrong, my total number of users should be 4 but listed as 5 from this script. I will post a screenshot. I know how to count total users including system users is just: getent passwd | wc -l

awk -F: '$3 >= 1000 { C++ } END { print C+0 }' /etc/passwd

Advertisement

Answer

Add ; print just after C++ in order to control which users are concerned by your filter:

awk -F: '$3 >= 1000 { C++; print } END { print C+0 }' /etc/passwd

The output contains:

  • nobody
  • mahandri
  • kingfoolish
  • Benteiversen
  • Geirgjerde
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement