Section Next | Prev


2.4.3 ファイルデータの表示( less, head, tail )

less
【機能説明】
cat コマンドはファイルの内容を一気に表示するのに対し、 less コマンドは1画面ずつ表示させることができます。
また圧縮されたファイルや、 マニュアル用のフォーマット(nroff)を展開する機能を含みます。
従来このような用途には more が使われていましたが、機能拡張が進んだ less 普及しています。

【入力フォーマット】
less ファイル名

【主なオプション】
less はサブコマンドを対話形式で指示することが出来ます。
コマンド意味
<SPACE>, ^V, f, ^F1画面ページを送る(進める)。
d, ^D1/2画面分送る
<Enter>, ^N, j, ^J1行送る
y, ^Y, k, ^K1行戻る
u, ^U1/2画面分戻る
b, ^B1画面分ページを戻る。
1G先頭に戻る
G末尾に移動
hヘルプの表示
q終了

less の前身である more はページを送る機能しかありませんでしたが、 改良版の less はページを戻ったり、圧縮ファイルを展開しながら表示したり、 文字列検索を行ったりと飛躍的に強力になっています。

/usr/share/man/man1/ls.1.gz を more で参照した例

[student@h006 ~]$ zcat /usr/share/man/man1/ls.1.gz  | more
.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.43.3.
.TH LS "1" "April 2018" "GNU coreutils 8.22" "User Commands"
.SH NAME
ls \- list directory contents
.SH SYNOPSIS
.B ls
[\fIOPTION\fR]... [\fIFILE\fR]...
.SH DESCRIPTION
.\" Add any additional description here
.PP
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of \fB\-cftuvSUX\fR nor \fB\-\-sort\fR is sp
ecified.
.PP
Mandatory arguments to long options are mandatory for short options too.
.TP
\fB\-a\fR, \fB\-\-all\fR
do not ignore entries starting with .
.TP
\fB\-A\fR, \fB\-\-almost\-all\fR
do not list implied . and ..
.TP
\fB\-\-author\fR
--続ける--

head

【機能説明】
head はファイルの先頭から指定された行数分表示します。

【入力フォーマット】
less [ オプション ] ファイル名

【主なオプション】
-nn
ファイルの先頭から n行を表示する。n を用いず直接、行数を指定することも可能。

【実行例】
# passwd(5) の先頭5行を表示
[student@h006 ~]$ head -n5 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

[student@h006 ~]$ head -3 /etc/group
root:x:0:
bin:x:1:
daemon:x:2:


tail

【機能説明】
tail はファイルの末尾から指定された行数分表示します。

【入力フォーマット】
tail [ オプション ] ファイル名

【主なオプション】
-nn
ファイルの末尾から n行を表示する。n を用いず直接、行数を指定することも可能。
-f
ファイル末尾を表示しつづける(行が追加されるごとに、追加分を表示)

【実行例】
# passwd(5)の後ろから3行を表示
[student@h006 ~]$ tail -3 /etc/passwd
gluster:x:988:982:GlusterFS daemons:/var/run/gluster:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin

# ログファイルを表示しつづける
[student@h006 ~]$ tail -f /var/log/dmesg
[   23.089932] device-mapper: table: 253:2: adding target device sda2 caused an alignment inconsistency: physical_block_size=4096, logical_block_size=512, alignment_offset=0, start=113246720
[   23.451856] XFS (sda1): Mounting V5 Filesystem
[   24.235995] XFS (dm-2): Mounting V5 Filesystem


Section Next | Prev

Copyright 2007-2018 ycosSystems GettingStart/Body243.html