w, last, wall コマンド

この記事は [Linux コマンド 全部オレ Advent Calendar 2017](https://adventar.org/calendars/2630) の4日目の記事です。

# w

```
NAME
       w - Show who is logged on and what they are doing.

SYNOPSIS
       w - [husfiV] [user]

DESCRIPTION
       w  displays  information  about  the users currently on the machine, and their pro-
       cesses.  The header shows, in this order,  the current time, how  long  the  system
       has been running, how many users are currently logged on, and the system load aver-
       ages for the past 1, 5, and 15 minutes.

       The following entries are displayed for each user: login name, the  tty  name,  the
       remote  host, login time, idle time, JCPU, PCPU, and the command line of their cur-
       rent process.

       The JCPU time is the time used by all processes attached to the tty.  It  does  not
       include past background jobs, but does include currently running background jobs.

       The PCPU time is the time used by the current process, named in the "what" field.
```
今、誰がログインして、何をしているか確認できるコマンド。

## よく使いそうな使い方

```
[sinsengumi ~]$ w
 10:41:49 up 12 days, 23:13,  2 users,  load average: 0.00, 0.01, 0.05
USER       TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
sinsengumi pts/0    10.128.218.63    10:36    5.00s  0.04s  0.00s sleep 20
sinsengumi pts/1    10.128.218.63    10:36    5.00s  0.06s  0.00s w
```
ログインしているユーザが動かしているプロセスが確認できる（WHAT列）。
なお、ここに表示されるのはフォアグラウンドのプロセスだけでバックグラウンドで動かしたプロセスは表示されない。

# last

```
NAME
       last, lastb - show listing of last logged in users

SYNOPSIS
       last [-R] [-num] [ -n num ] [-adFiowx] [ -f file ] [ -t YYYYMMDDHHMMSS ] [name...]  [tty...]
       lastb [-R] [-num] [ -n num ] [ -f file ] [-adFiowx] [name...]  [tty...]

DESCRIPTION
       Last  searches back through the file /var/log/wtmp (or the file designated by the -f flag) and displays a list
       of all users logged in (and out) since that file was created.  Names of users and tty's can be given, in which
       case  last will show only those entries matching the arguments.  Names of ttys can be abbreviated, thus last 0
       is the same as last tty0.

       When last catches a SIGINT signal (generated by the interrupt key, usually  control-C)  or  a  SIGQUIT  signal
       (generated  by  the  quit key, usually control-\), last will show how far it has searched through the file; in
       the case of the SIGINT signal last will then terminate.

       The pseudo user reboot logs in each time the system is rebooted.  Thus last reboot will  show  a  log  of  all
       reboots since the log file was created.

       Lastb is the same as last, except that by default it shows a log of the file /var/log/btmp, which contains all
       the bad login attempts.
```
最近ログインしたユーザーの情報を表示する。`/var/log/wtmp` の情報から取っている。

## よく使いそうな使い方

```
[sinsengumi ~]$ last -F | head
sinsengumi pts/1        10.128.218.63    Mon Dec  4 10:36   still logged in
sinsengumi pts/0        10.128.218.63    Mon Dec  4 10:36   still logged in
sinsengumi pts/0        10.128.218.44    Sun Dec  3 13:28 - 13:32  (00:04)
sinsengumi pts/0        10.128.218.44    Sat Dec  2 22:21 - 22:35  (00:14)
sinsengumi pts/1        10.128.218.44    Sat Dec  2 20:30 - 20:59  (00:29)
sinsengumi pts/0        10.128.218.44    Sat Dec  2 19:24 - 20:59  (01:35)
sinsengumi pts/1        10.128.218.44    Fri Dec  1 14:17 - 16:43  (02:26)
sinsengumi pts/0        10.128.218.44    Fri Dec  1 14:16 - 16:42  (02:25)
sinsengumi pts/1        10.128.218.44    Fri Dec  1 12:49 - 13:02  (00:12)
sinsengumi pts/0        10.128.218.44    Fri Dec  1 12:45 - 13:01  (00:15)
```

# wall

```
NAME
       wall -- send a message to everybody's terminal.

SYNOPSIS
       wall [-n] [ message ]

DESCRIPTION
       Wall  sends  a  message  to  everybody logged in with their mesg(1) permission set to yes.  The message can be
       given as an argument to wall, or it can be sent to wall's standard input.  When using the standard input  from
       a terminal, the message should be terminated with the EOF key (usually Control-D).

       The length of the message is limited to 20 lines.  For every invocation of wall a notification will be written
       to syslog, with facility LOG_USER and level LOG_INFO.
```
接続している全端末にメッセージを送ることができる。

## よく使いそうな使い方

```
[sinsengumi ~]$ wall Hello, World!
[sinsengumi ~]$
Broadcast message from sinsengumi@hoge (pts/1) (Mon Dec  4 10:55:38 2017):

Hello, World!
```
自分にも送られる。