Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Hello friend, what’s the shortest Linux command you’ve ever seen? Can you think of a single letter Linux command? For this article we’ll go into the short and snappy W command.

Rich in meaningw

Tips: A small W command, which bears more weight than its puny body can bear, produces as much output as the following commands combined.

  • Date (time print)
  • Uptime (uptime + load)
  • Who (List of logged in users)

Is not stunned, it all the meaning of the summary into a sentence, who, what?

decompositionw

That’s a pretty simple command. One W says everything. Who else?

$w
Copy the code

The following output is displayed:

 19:13:05 up 6 days,  5:23,  1 user,  load average: 0.39, 0.44, 0.38
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    182.148.112.32   09:58    0.00s  0.04s  0.00s w
Copy the code

For this server, I logged in to one user, so it only shows what one user did, so what about another one?

19:14:39 up 6 days, 5:24, 2 users, load average: 0.34, 0.39, 0.36 USER TTY FROM login@idle JCPU PCPU WHAT root PTS /0 182.148.112.32 09:58 1:270.04s 0.04s -bash root PTS /1 2.00s 0.0s 0.00s wCopy the code

This shows what two users are doing. So let’s parse the output layer by layer.

The first line

  • 19:13:05, represents the current time, which is equivalent to usingdateCommand.
  • Up 6 days, 5:24 = 6 days, 5 hours and 24 minutes This time refers to the time until the startup login. The equivalent of usinguptimeCommand.
  • Load Average: 0.34, 0.39, 0.36, indicating average load. The three values represent average load of 1 minute, 5 minutes, and 15 minutes respectively.

What is load averaging for Linux? It actually represents the average number of active processes over a period of time, that is, the number of processes using the CPU processor. For example, “load averaged 0.34 per minute” means that the processor was used by an average of 0.34 processes in the last minute, and further, the processor was active 34% of the time.

The load average is closely related to the number of CPU cores. The higher the number of cores, the higher the load average is. For example, if the number of cores is 8, the load average can reach 7 or even 8. So what does this value mean? If the load approaches or exceeds the core count, your machine is dangerously overloaded. For easy visualization, we can use the tload command to output the load graph.

The first line is so informative that a simple uptime command could have done it.

$uptime
Copy the code

The output is shown below, completely overlapping.

Up 6 days, 6:02, 2 Users, load average: 0.45, 0.52, 0.47Copy the code

The third line

The whole meaning of the second line is actually the information of the login user. We can use the who command instead.

$who
Copy the code

The output is

Root PTS /0 2021-09-29 09:58 (182.148.112.32) Root PTS /1 2021-09-29 08:14 (182.148.112.32)Copy the code

But it is not as detailed as the W command, whose entire line has the following meanings

  • USER: indicates the USER name
  • TTY means local
  • FROM indicates the IP address of the server to which the user is connected
  • Login@ indicates the time when the user connects to the system
  • IDLE indicates how long the user has not been active
  • WHAT represents the program that the user is currently running

This is a complete breakdown of the W command. Although the W command looks useful, there are still a lot of details that are not given. We can use the ps and top commands to further supplement the system process information.