▼すべてを開く。
▲すべてを閉じる。
$ head -n 15 message.log Jul 25 15:47:37 localhost syslogd 1.4.1: restart. Jul 25 15:52:07 localhost login(pam_unix)[2590]: authentication failure; logname= uid=0 euid=0 tty=pts/1 ruser= rhost=192.168.0.3 user=masay Jul 25 15:52:10 localhost login[2590]: FAILED LOGIN 1 FROM 192.168.0.3 FOR masay, Authentication failure Jul 25 15:52:15 localhost login(pam_unix)[2590]: session opened for user masay by (uid=0) Jul 25 15:52:15 localhost -- masay[2590]: LOGIN ON pts/1 BY masay FROM 192.168.0.3 Jul 25 15:53:44 localhost kernel: hda: dma_intr: status=0x51 { DriveReady SeekComplete Error } Jul 25 15:53:44 localhost kernel: hda: dma_intr: error=0x84 { DriveStatusError BadCRC } Jul 25 17:33:05 localhost login(pam_unix)[2590]: session closed for user masay Jul 25 17:33:33 localhost gdm(pam_unix)[1969]: session closed for user masay Jul 25 17:33:35 localhost cannaserver[1847]: [masay] Read request failed Jul 25 17:33:43 localhost gconfd (masay-2035): GConf ?202??203??203\220?203??201\214使?224??201\225?202\214?201??201\204?201??201\233?202\223?200\202?202??203??203\203?203\210?203\200?202??203??201\227?201??201\231?200\202 Jul 25 17:33:43 localhost gconfd (masay-2035): ?202?206?201\227?201??201\231?200\202 Jul 26 14:48:55 localhost syslogd 1.4.1: restart. Jul 26 14:48:55 localhost syslog: syslogd startup succeeded Jul 26 14:48:55 localhost kernel: klogd 1.4.1, log source = /proc/kmsg started.
headコマンドで-nオプションを指定し、表示する行数「15」ファイル名「message.log」を指定して実行すると、ファイルの先頭から15行を表示する。どのような内容かを簡単に確認する時に使う。すべてを見る場合は、moreやlessなどのコマンドを使う。
$ head message.log Jul 25 15:47:37 localhost syslogd 1.4.1: restart. Jul 25 15:52:07 localhost login(pam_unix)[2590]: authentication failure; logname= uid=0 euid=0 tty=pts/1 ruser= rhost=192.168.0.3 user=masay Jul 25 15:52:10 localhost login[2590]: FAILED LOGIN 1 FROM 192.168.0.3 FOR masay, Authentication failure Jul 25 15:52:15 localhost login(pam_unix)[2590]: session opened for user masay by (uid=0) Jul 25 15:52:15 localhost -- masay[2590]: LOGIN ON pts/1 BY masay FROM 192.168.0.3 Jul 25 15:53:44 localhost kernel: hda: dma_intr: status=0x51 { DriveReady SeekComplete Error } Jul 25 15:53:44 localhost kernel: hda: dma_intr: error=0x84 { DriveStatusError BadCRC } Jul 25 17:33:05 localhost login(pam_unix)[2590]: session closed for user masay Jul 25 17:33:33 localhost gdm(pam_unix)[1969]: session closed for user masay Jul 25 17:33:35 localhost cannaserver[1847]: [masay] Read request failed
headコマンドでファイル「message.log」を指定して実行すると、ファイルの先頭から10行を表示する。どのような内容かを簡単に確認する時に使う。すべてを見る場合は、moreやlessなどのコマンドを使う。
$ less -m boot.log Apr 6 13:44:46 localhost xinetd: xinetd startup succeeded Apr 6 13:44:49 localhost sendmail: sendmail startup succeeded Apr 6 13:44:49 localhost sendmail: sm-client startup succeeded Apr 6 13:44:49 localhost gpm: gpm startup succeeded Apr 6 13:44:52 localhost canna: succeeded Apr 6 13:44:52 localhost crond: crond startup succeeded Apr 6 13:44:57 localhost xfs: xfs startup succeeded Apr 6 13:44:57 localhost atd: atd startup succeeded Apr 6 13:44:58 localhost firstboot: . Apr 6 13:44:59 localhost firstboot: Apr 6 13:44:59 localhost firstboot: XFree86 Version 4.3.0 Apr 6 13:44:59 localhost firstboot: (Red Hat Enterprise Linux release: 4.3.0-35.EL) boot.log 3%
lessコマンドで-mオプションと表示するファイル「boot.log」を指定すると、ファイルの内容が表示され、最下段にファイルの先頭から何%の部分かが表示される。
画面制御のキー操作 | |||
戻る | 進む | ||
---|---|---|---|
1行戻る | y | 1行進む | [Return] |
半画面戻る | u | 半画面進む | d |
1画面戻る | b | 1画面進む | [Space] |
1行目に戻る | g | 最終行に進む | G |
情報表示のキー操作 | |
行番号の表示 | -N [Return] |
行番号の非表示 | -N [Return] |
表示位置の表示 | -m |
表示位置の表示(詳細) | -M |
$ less -M boot.log Apr 6 13:44:46 localhost xinetd: xinetd startup succeeded Apr 6 13:44:49 localhost sendmail: sendmail startup succeeded Apr 6 13:44:49 localhost sendmail: sm-client startup succeeded Apr 6 13:44:49 localhost gpm: gpm startup succeeded Apr 6 13:44:52 localhost canna: succeeded Apr 6 13:44:52 localhost crond: crond startup succeeded Apr 6 13:44:57 localhost xfs: xfs startup succeeded Apr 6 13:44:57 localhost atd: atd startup succeeded Apr 6 13:44:58 localhost firstboot: . Apr 6 13:44:59 localhost firstboot: Apr 6 13:44:59 localhost firstboot: XFree86 Version 4.3.0 Apr 6 13:44:59 localhost firstboot: (Red Hat Enterprise Linux release: 4.3.0-35.EL) boot.log lines 1-53/1988 3%
lessコマンドで-Mオプションと表示するファイル「boot.log」を指定すると、ファイルの内容が表示され、最下段にファイルのどの部分が表示されているかが表示される。
この例では、1-53が現在表示されている部分の行番号、1988がファイルの全行数、3%がファイルの先頭から表示されている部分の割合を示す。
画面制御のキー操作 | |||
戻る | 進む | ||
---|---|---|---|
1行戻る | y | 1行進む | [Return] |
半画面戻る | u | 半画面進む | d |
1画面戻る | b | 1画面進む | [Space] |
1行目に戻る | g | 最終行に進む | G |
情報表示のキー操作 | |
行番号の表示 | -N [Return] |
行番号の非表示 | -N [Return] |
表示位置の表示 | -m |
表示位置の表示(詳細) | -M |
$ more file
moreコマンドでファイル「file」を指定すると、ファイルの内容を画面単位で表示する。
画面制御のキー操作 | |||
戻る | 進む | ||
---|---|---|---|
1画面戻る | b | 1画面進む | [Space] |
1行進む | [Return] | ||
半画面進む | d |
moreの終了 | q |
現在は、多機能なlessコマンドのほうがよく使われている。
$ less -N boot.log 1 Apr 6 13:44:30 localhost syslog: syslogd startup succeeded 2 Apr 6 13:44:30 localhost syslog: klogd startup succeeded 3 Apr 6 13:44:30 localhost irqbalance: irqbalance startup succeeded 4 Apr 6 13:44:30 localhost portmap: portmap startup succeeded 5 Apr 6 13:44:31 localhost nfslock: rpc.statd startup succeeded 6 Apr 6 13:44:31 localhost keytable: Loading keymap: 7 Apr 6 13:44:31 localhost keytable: 8 Apr 6 13:44:31 localhost keytable: 9 Apr 6 13:44:31 localhost rc: Starting keytable: succeeded 10 Apr 6 13:44:32 localhost random: Initializing random number generator: 10 succeeded
lessコマンドで-Nオプションと表示するファイル「boot.log」を指定すると、ファイルの内容が行番号付きで表示される。
画面制御のキー操作 | |||
戻る | 進む | ||
---|---|---|---|
1行戻る | y | 1行進む | [Return] |
半画面戻る | u | 半画面進む | d |
1画面戻る | b | 1画面進む | [Space] |
1行目に戻る | g | 最終行に進む | G |
情報表示のキー操作 | |
行番号の表示 | -N [Return] |
行番号の非表示 | -N [Return] |
表示位置の表示 | -m |
表示位置の表示(詳細) | -M |
$ less boot.log Apr 6 13:44:46 localhost xinetd: xinetd startup succeeded Apr 6 13:44:49 localhost sendmail: sendmail startup succeeded Apr 6 13:44:49 localhost sendmail: sm-client startup succeeded Apr 6 13:44:49 localhost gpm: gpm startup succeeded Apr 6 13:44:52 localhost canna: succeeded Apr 6 13:44:52 localhost crond: crond startup succeeded Apr 6 13:44:57 localhost xfs: xfs startup succeeded Apr 6 13:44:57 localhost atd: atd startup succeeded Apr 6 13:44:58 localhost firstboot: . Apr 6 13:44:59 localhost firstboot: Apr 6 13:44:59 localhost firstboot: XFree86 Version 4.3.0 Apr 6 13:44:59 localhost firstboot: (Red Hat Enterprise Linux release: 4.3.0-35.EL) /xinetd
lessコマンド実行中に、最下行に表示されるプロンプト「:」部分に「/」に続いて検索する文字列を入力してリターンを押す。すると、該当する部分に移動し、検索された文字列が反転表示される。該当する文字列がなかった場合は、「Pattern not found (press RETURN)」と表示される。表示画面の2行目以降にあるパターンにマッチする行を検索する。
検索制御のキー操作 | |
次検索 | n |
元に戻る | N |
検索の終了 | Esc-u |
画面制御のキー操作 | |||
戻る | 進む | ||
---|---|---|---|
1行戻る | y | 1行進む | [Return] |
半画面戻る | u | 半画面進む | d |
1画面戻る | b | 1画面進む | [Space] |
1行目に戻る | g | 最終行に進む | G |
情報表示のキー操作 | |
行番号の表示 | -N [Return] |
行番号の非表示 | -N [Return] |
表示位置の表示 | -m |
表示位置の表示(詳細) | -M |
$ cat a.txt ********************************************************************* * ファイル「a.txt」の内容 * ********************************************************************* テキストのおわり
catコマンドでファイル名「a.txt」を指示して実行すると、a.txtの内容が表示される。catコマンドでは、moreやlessなどのようにファイルの表示を制御できないので、内容が一度に表示されてしまう。内容が一画面を越える場合、途中で止めて見ることはできない。
$ less boot.log Apr 6 13:44:30 localhost syslog: syslogd startup succeeded Apr 6 13:44:30 localhost syslog: klogd startup succeeded Apr 6 13:44:30 localhost irqbalance: irqbalance startup succeeded Apr 6 13:44:30 localhost portmap: portmap startup succeeded Apr 6 13:44:31 localhost nfslock: rpc.statd startup succeeded Apr 6 13:44:31 localhost keytable: Loading keymap: Apr 6 13:44:31 localhost keytable: Apr 6 13:44:31 localhost keytable: Apr 6 13:44:31 localhost rc: Starting keytable: succeeded Apr 6 13:44:32 localhost random: Initializing random number generator: succeeded
lessコマンドで、内容を表示するファイル「boot.log」を指定して実行すると、ファイルが1画面単位で表示される。画面表示を制御するには次のキーを使う。
画面制御のキー操作 | |||
戻る | 進む | ||
---|---|---|---|
1行戻る | y | 1行進む | [Return] |
半画面戻る | u | 半画面進む | d |
1画面戻る | b | 1画面進む | [Space] |
1行目に戻る | g | 最終行に進む | G |
情報表示のキー操作 | |
行番号の表示 | -N [Return] |
行番号の非表示 | -N [Return] |
表示位置の表示 | -m |
表示位置の表示(詳細) | -M |
$ tail -n 15 boot.log Jun 15 12:01:20 polotxp cups: cupsd startup succeeded Jun 15 12:01:21 polotxp sshd: succeeded Jun 15 12:01:21 polotxp xinetd: xinetd startup succeeded Jun 15 12:01:22 polotxp ntpd: succeeded Jun 15 12:01:21 polotxp last message repeated 2 times Jun 15 12:01:21 polotxp ntpd: ntpd startup succeeded Jun 15 12:03:24 polotxp sendmail: sendmail startup succeeded Jun 15 12:04:24 polotxp sendmail: sm-client startup succeeded Jun 15 12:04:26 polotxp canna: succeeded Jun 15 12:04:26 polotxp crond: crond startup succeeded Jun 15 12:04:27 polotxp xfs: xfs startup succeeded Jun 15 12:04:27 polotxp atd: atd startup succeeded Jun 15 12:04:28 polotxp rhnsd: rhnsd startup succeeded Jun 15 12:04:28 polotxp mdmonitor: mdadm startup succeeded Jun 15 12:04:28 polotxp mdmonitor: mdadm succeeded
tailコマンドで-nオプションを指定し、表示する行数「15」と表示するファイル「boot.log」を指示すると、「boot.log」の最後の15行が表示される。
$ tail boot.log Jun 15 12:01:21 polotxp ntpd: ntpd startup succeeded Jun 15 12:03:24 polotxp sendmail: sendmail startup succeeded Jun 15 12:04:24 polotxp sendmail: sm-client startup succeeded Jun 15 12:04:26 polotxp canna: succeeded Jun 15 12:04:26 polotxp crond: crond startup succeeded Jun 15 12:04:27 polotxp xfs: xfs startup succeeded Jun 15 12:04:27 polotxp atd: atd startup succeeded Jun 15 12:04:28 polotxp rhnsd: rhnsd startup succeeded Jun 15 12:04:28 polotxp mdmonitor: mdadm startup succeeded Jun 15 12:04:28 polotxp mdmonitor: mdadm succeeded
tailコマンドで表示するファイル「boot.log」を指示すると、ファイルの最後の10行が表示される。
$ ls nmbd.log smbd.log
$ tail *.log ==> nmbd.log <== Netbios nameserver version 3.0.9-1.3E.3 started. Copyright Andrew Tridgell and the Samba Team 1994-2004 [2005/06/02 21:45:32, 0] nmbd/nmbd_become_lmb.c:become_local_master_stage2(396) ***** Samba name server POLOTXP is now a local master browser for workgroup MYGROUP on subnet 192.168.0.9 ***** [2005/06/02 22:30:30, 0] nmbd/nmbd.c:terminate(56) Got SIGTERM: going down... ==> smbd.log <== [2005/06/02 21:39:42, 0] smbd/server.c:main(760) smbd version 3.0.9-1.3E.3 started. Copyright Andrew Tridgell and the Samba Team 1992-2004 [2005/06/02 21:42:04, 1] smbd/server.c:open_sockets_smbd(348) Reloading services after SIGHUP [2005/06/02 21:42:04, 1] printing/printing.c:start_background_queue(1363) Reloading services after SIGHUP [2005/06/02 21:42:29, 1] smbd/server.c:open_sockets_smbd(348) Reloading services after SIGHUP
tailコマンドで、表示するファイルを「*.log」で指定すると、指定された複数のファイルの末尾10行がそれぞれ表示される。複数ファイルの内容を確認したい場合などに役立つ。