uptime and w commands in Linux

  • Post author:
  • Post last modified:August 25, 2023
  • Reading time:3 mins read

The uptime and w commands in Linux and Unix systems give pointed information about the system uptime, load average and about logged in users.

uptime

The uptime command is given as,

uptime

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.

w

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    LOGIN@   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 WHAT.

The w command syntax is,

w [-husfVo] [user]

and the options are,

w – Command Line Options
OptionDescription
-hdo not print the header
-uignore username while reporting current process.
-suse the short format. Login time, JCPU and PCPU are not printed.
-fdo not print the FROM (remote hostname) field
-Vprint version number
-oprint in old style. For times less than one minute, spaces are printed.
userprint information for the given user

who

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.

Share

Karunesh Johri

Software developer, working with C and Linux.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments