Topic
6 replies Latest Post - ‏2010-10-01T13:30:29Z by santosh_linux
SystemAdmin
SystemAdmin
232 Posts
ACCEPTED ANSWER

Pinned topic help on basic sys admin command

‏2007-08-13T10:01:31Z |

Hi All,

Can you Please tell me which command I should use to see total number of users on a Linus Server, including those who are not currently also logged in.

I have tried users and who command but these commands only lists the currently logged in users info.

I want to see all the users, i.e., total number of users on Linux Server.

Thanks in Advance for your Help & Cooperation.

Thanks & Warm Regards.
Indranil.
Updated on 2010-10-01T13:30:29Z at 2010-10-01T13:30:29Z by santosh_linux
  • SystemAdmin
    SystemAdmin
    232 Posts
    ACCEPTED ANSWER

    Re: help on basic sys admin command

    ‏2007-08-27T07:44:24Z  in response to SystemAdmin
    You can see /etc/passwd file for defined users in the system.
  • SystemAdmin
    SystemAdmin
    232 Posts
    ACCEPTED ANSWER

    Re: help on basic sys admin command

    ‏2008-11-26T18:37:20Z  in response to SystemAdmin
    You can use this command

    cat <path of the passwd file> | wc -option

    example:
    #cat /etc/passwd |wc -l
    39

    so totally 39 lines in the password file so you can assume 39 users are there, but if there any commented lines are then it ll count that line also.. so after getting this you can verify

    or you can write a small script and get the exact no of users

    Govindasamy
  • SystemAdmin
    SystemAdmin
    232 Posts
    ACCEPTED ANSWER

    Re: help on basic sys admin command

    ‏2009-06-21T18:22:21Z  in response to SystemAdmin
    Use $cat -n /etc/passwd command it will number all the lines in the file so that you can calculate the no. of users.
  • Srikrishan
    Srikrishan
    1 Post
    ACCEPTED ANSWER

    Re: help on basic sys admin command

    ‏2010-06-23T04:46:24Z  in response to SystemAdmin
    cat /etc/passwd | grep -v nologin

    should give the the number of users who can login to the system.
    • MichalKopyta
      MichalKopyta
      1 Post
      ACCEPTED ANSWER

      Re: help on basic sys admin command

      ‏2010-07-23T05:30:47Z  in response to Srikrishan
      Well I would write something like that (works in most cases)

      cat /etc/passwd | grep home

      there are many fake users on each machine (postgresql, mysql, httpd and other) which have got no home directory - and this command will not list them.
  • santosh_linux
    santosh_linux
    4 Posts
    ACCEPTED ANSWER

    Re: help on basic sys admin command

    ‏2010-10-01T13:30:29Z  in response to SystemAdmin
    Most of the times we have userid more than uid 100 as the normal users. u can use this one liner to help you out.

    cat /etc/passwd|egrep -v '^#|nologin'|awk -F: '{if ( $3 > 100) { print $1 }}'

    it will read the passwd file, remove any lines starting with hash or having nologin , later it will check for uid which are greater than 100 and print the user names.

    Thanks,
    Santosh