Who command in UNIX

Posted in

Who command in UNIX
vinaykhatri

Vinay Khatri
Last updated on November 21, 2024

    In this article, we will be going through the who command in Unix Operating System. This is a widely used command that can provide information related to processes, users, and run levels of the Operating System. We will also go through what is run levels output by this command and a few examples to demonstrate the working.

    What is the use of the who command in Unix?

    It is very helpful for UNIX and UNIX-like system users which tells you the following information regarding the Operating System.

    • Time spent since the last boot
    • The information of currently logged in users
    • The run level of the system currently

    The syntax is:

    $ who <options> <file>

    It prints the following attributes of the users with no option provided:

    • Name of the respective users
    • Terminal Line numbers
    • Login time of each user
    • The remote host username for each user

    Below is the output of the command without any option:

    What are run levels?

    Runlevels are the several predefined complexity levels of the operating system.

    • Runlevel 0: Power is turned off.
    • Runlevel 1: single-user root mode; no network, no extras, just get root into the system - commonly used as "recovery mode" to remedy things that went wrong but not disastrously (horribly wrong usually requires live media boot to fix).
    • Runlevel 2: Denotes a multi-user environment with no network connectivity. Because the network isn't enabled, many people can log in, but they must do so from the local console.
    • Runlevel 3: Networked multi-user. Multiple users, including those from faraway systems, can log in (e.g., via SSH). This is an example of a Text User Interface (TUI)/command-line interface run level.
    • Runlevel 4: This may be altered in any way you desire - pretty much anything goes.
    • Runlevel 5: Graphical User Interface (GUI), multi-user with a network; this provides a graphical login screen and defaults to a graphical desktop interface rather than a plain text terminal.
    • Runlevel 6: Restart

    Examples

    1. Display the current run-level of the system

    $ who -r

    Output: Display the current run-level of the system

    2. Display details of currently logged-in users

    $ who -a

    Output: Display details of currently logged-in users

    3. To list the active processes spawned by the INIT:

    $ who -p -H

    Output: To list the active processes spawned by the INIT

    4. To see the list of users currently logged in to the system:

    $ who -u

    Output: To see the list of users currently logged in to the system

    5. Time at which the system booted last

    $ who -b -H

    Output: Time at which the system booted last

    6. To get the list of dead processes

    $ who -d -H

    To get the list of dead processes

    7. To get a count of currently logged in users

    $ who -q -H

    Output : To get a count of currently logged in users

    Conclusion

    We discussed the who command of UNIX and UNIX-like Operating Systems which you can use to get information related to users and run levels. It also provides various options to track the count of users, time of boot and logins, processes, etc. related to the Operating System.

    People are also reading:

    Leave a Comment on this Post

    0 Comments