-CentOS- | -Ubuntu-
ファイルの冒頭部分を参照する
「head」コマンド
主なオプション名 |
説明 |
-行数 |
指定した行数を指定する。デフォルトは10行。 |
-n 行数 |
指定した行数を指定する。デフォルトは10行。 |
–lines=行数 |
指定した行数を指定する。デフォルトは10行。 |
headコマンドの実行1
$ head file.txt
test[1行目]
test[2行目]
test[3行目]
test[4行目]
test[5行目]
test[6行目]
test[7行目]
test[8行目]
test[9行目]
test[10行目] -1-
- デフォルトは10行で表示する。
headコマンドの実行2
$ head file.txt
test[1行目]
-1-
test[2行目]
-1-
test[3行目]
test[4行目]
test[5行目]
test[6行目]
test[7行目]
test[8行目]
- 空行も表示される。
-5オプションをつけて実行
$ head -5 file.txt
test[1行目]
test[2行目]
test[3行目]
test[4行目]
test[5行目]
-n 5オプションをつけて実行
$ head -n 5 file.txt
test[1行目]
test[2行目]
test[3行目]
test[4行目]
test[5行目]
–lines=5オプションをつけて実行
$ head –lines=5 file.txt
test[1行目]
test[2行目]
test[3行目]
test[4行目]
test[5行目]
ファイルの末尾部分の参照する
「tail」コマンド
主なオプション名 |
説明 |
-行数 |
指定した行数を指定する。デフォルトは10行。 |
-n 行数 |
指定した行数を指定する。デフォルトは10行。 |
–lines=行数 |
指定した行数を指定する。デフォルトは10行。 |
tailコマンドの実行1
$ tail file.txt
test[6行目] -1-
test[7行目]
test[8行目]
test[9行目]
test[10行目]
test[11行目]
test[12行目]
test[13行目]
test[14行目]
test[15行目]
- デフォルトは10行で表示する。
tailコマンドの実行2
$ tail file.txt
test[8行目]
test[9行目]
test[10行目]
test[11行目]
test[12行目]
-1-
test[13行目]
-1-
test[14行目]
test[15行目]
- 空行も表示される。
-5オプションをつけて実行
$ tail -5 file.txt
test[11行目]
test[12行目]
test[13行目]
test[14行目]
test[15行目]
-n 5オプションをつけて実行
$ tail -n 5 file.txt
test[11行目]
test[12行目]
test[13行目]
test[14行目]
test[15行目]
–lines=5オプションをつけて実行
$ tail –lines=5 file.txt
test[11行目]
test[12行目]
test[13行目]
test[14行目]
test[15行目]
参照元情報

LinuCレベル1 合格教本