Linux commands to print the number of users & number of processes!!?

Discussion in 'Command Line' started by m7com, Apr 30, 2014.

  1. m7com

    m7com New Member

    Joined:
    Apr 30, 2014
    Messages:
    1
    Likes Received:
    1
    Hello
    How R U every one ??
    i have a small Q about two Commands >> Are There a command for :
    Print out the number of all running processes on the system

    And
    Are There a command for :
    Print out the number of all users defined on the system

    i just need this two commands please if it exist.
    i need it in bash shell .. Linux operating system

    Thank you very much,, happy to become a member in this great forum .


     
    bashcommando likes this.
  2. bashcommando

    bashcommando Active Member

    Joined:
    Jan 28, 2014
    Messages:
    223
    Likes Received:
    49
    You can make a user counter by:
    Count the number of lines in the /etc/passwd file
    First you would need to read the file into a variable by using:
    Code:
    export users=`cat /etc/passwd`
    Then just count the lines:
    Code:
    export num=`echo "$users" | wc -l`
    Then the number is stored in a nice little variable called num. To call it use $num.
    As for the processes, use
    Code:
    export running=`ps -ef|wc -l`
    Then use $running to get the number
     
  3. Jeremy

    Jeremy Member

    Joined:
    Sep 5, 2013
    Messages:
    34
    Likes Received:
    20
    Total number of users or number of currently logged in users?
    If you want the total users bashcommando's should help, if you need the current logged in try the "who" command.
     
    bashcommando likes this.
  4. GrumpyOldMan

    GrumpyOldMan Active Member

    Joined:
    Oct 30, 2013
    Messages:
    220
    Likes Received:
    62
    Doing homework are you?
     
  5. bashcommando

    bashcommando Active Member

    Joined:
    Jan 28, 2014
    Messages:
    223
    Likes Received:
    49
    I live on the computer. I am on it from 6-12 hours a day. LOL
     

Share This Page