The uptime and w commands in Linux and Unix systems give pointed information about the system uptime, load average and about logged in users.
The uptime command is given as,
And the output is like,
07:47:08 up 25 days, 17:54, 1 user, load average: 0.03, 0.09, 0.08
In the above output, 07:47:08 is the timestamp at the time the command was given. Next is the uptime. The system had been up (time since the last boot) for 25 days, 17 hours and 54 minutes. There was one user logged in at that time. And the three load average figures were 0.03, 0.09, 0.08.
The w command gives information about the logged in users. For example,
$ w 15:57:21 up 10:30, 2 users, load average: 0.08, 0.11, 0.13 USER TTY FROM [email protected] IDLE JCPU PCPU WHAT user1 pts/0 :0 11:26 18.00s 0.66s 0.66s bash user1 pts/1 :0 14:36 0.00s 0.79s 0.01s w
The header comprises of two lines. The first line is the same as that given by the uptime command. The second line gives column headings. Then, we have the information about the logged-in users. The columns are user-id, tty, remote host, login time, idle time, JCPU, PCPU and the command line of the current process executed by the user. The
:0 under the
FROM column indicates a local user. Had the user been a remote user, the user's IP address would have been shown. The JCPU is the CPU time of all processes attached to the terminal. This includes the currently running background processes, if any. The PCPU is the CPU time of the current process, whose command line is shown under the column
The w command syntax is,
w [-husfVo] [user]
and the options are,
|-h||do not print the header|
|-u||ignore username while reporting current process.|
|-s||use the short format. Login time, JCPU and PCPU are not printed.|
|-f||do not print the FROM (remote hostname) field|
|-V||print version number|
|-o||print in old style. For times less than one minute, spaces are printed.|
|user||print information for the given user|
Similar to w is the who command, which shows the users logged into the system. Unlike w, who does not print what they are doing. That is, the current process command line and the idle, JCPU and PCPU times are not printed. Then, there is the who am i command which prints the user's real user-id. Also, there is the whoami command, which prints the user's effective user-id.