TrumanWong

who

Displays information about all currently logged in users.

Summary

who [OPTION]... [file] [am i]

The main purpose

  • When no non-option arguments are given, print information for each current user in the following field order: login user name, terminal information, login time, remote host, or X display.
  • When a user executes who am i, only the information of the user running the command is displayed.

Options

-a, --all is equivalent to calling '-b -d --login -p -r -t -T -u'.
-b, --boot The time when the system was last booted.
-d, --dead Print processes in dead status.
-H, --heading Print column header lines.
-l, --login Print system login process.
--lookup Attempt to canonicalize the hostname via DNS.
-m Display only hostnames and users associated with standard input.
-p, --process Print active processes spawned by init.
-q, --count List the names and counts of all logged-in users.
-r, --runlevel Print the current run level.
-s, --short Print name, line and time only (default).
-t, --time Print the last system clock change.
-T, -w, --mesg, --message, --writable Append one of '+, -, ?' as the user's message status to the end of the user name.
-u, --users List logged in users.
--help Display help information and exit.
--version Display version information and exit.

Regarding the '+, -, ?' of the -T option:
'+' allows writing information
'-' disables writing information
'?' The terminal device cannot be found

Parameters

file (optional): Specify file instead of the default /var/run/utmp and /etc/utmp; usually use /var/log/wtmp as a parameter to view users who have logged in to the system in the past.

return value

Returning 0 indicates success, returning a non-zero value indicates failure.

example

[root@localhost ~]# who
root pts/0 2013-08-19 15:04 (192.168.0.134)
root pts/1 2013-12-20 10:37 (180.111.155.40)

[root@localhost ~]# who -q
root root
# users=2

[root@localhost ~]# who -H
NAME LINE time COMMENT
root pts/0 2013-08-19 15:04 (192.168.0.134)
root pts/1 2013-12-20 10:37 (180.111.155.40)

[root@localhost ~]# who -w
root + pts/0 2013-08-19 15:04 (192.168.0.134)
root + pts/1 2013-12-20 10:37 (180.111.155.40)

Notice

  1. This command is a command in the GNU coreutils package. For related help information, please see man -s 1 who, info coreutils 'who invocation'.