形式
tail[-r][-b ブロック数|-c バイト数|-n 行数|-行数][パス名 ...]
機能
ファイルや標準入力の最後の部分を標準出力に出力します。デフォルトは標準入力です。入力のバイト単位,行単位またはブロック単位の位置から表示されます。指定した表示範囲のデータが存在しない場合でもエラーになりません。表示できるデータは表示されます。
引数
+符号のある数は入力の先頭からの位置を示します。例えば,-c +2は入力の先頭から2バイト目で表示を始めます。
-符号がある数字または符号のない数字は最後からの位置を示します。例えば,-n 2は入力の最後から2行目を示します。デフォルトは,-n 10または入力の最後の10行です。
戻り値
戻り値 | 意味 |
---|---|
0 | 正常終了 |
1以上 | エラー終了 |
注意事項
使用例
$ cat test1.txt
0001:test1.txt
0002:test1.txt
0003:test1.txt
0004:test1.txt
0005:test1.txt
0006:test1.txt
0007:test1.txt
0008:test1.txt
0009:test1.txt
0010:test1.txt
$ cat test2.txt
0001:test2.txt
0002:test2.txt
0003:test2.txt
0004:test2.txt
0005:test2.txt
0006:test2.txt
0007:test2.txt
0008:test2.txt
0009:test2.txt
0010:test2.txt
$ tail -n2 test1.txt test2.txt
==> test1.txt <==
0009:test1.txt
0010:test1.txt
==> test2.txt <==
0009:test2.txt
0010:test2.txt
$
$ cat test1.txt
0001:test1.txt
0002:test1.txt
0003:test1.txt
0004:test1.txt
0005:test1.txt
0006:test1.txt
0007:test1.txt
0008:test1.txt
0009:test1.txt
0010:test1.txt
$ tail -n+5 test1.txt
0005:test1.txt
0006:test1.txt
0007:test1.txt
0008:test1.txt
0009:test1.txt
0010:test1.txt
$
$ cat zztt1.txt
1:0001:zzzz:
2:0001:aaaa:
3:0001:JJJJ:
4:0001:cccc:
5:0001:cccc:
6:0001:cccc:
7:0001:cccc:
8:0001:cccc:
9:0001:cccc:
10:0001:cccc:
11:0001:cccc:
12:0001:cccc:
$ tail -r -n 2 zztt1.txt
12:0001:cccc:
11:0001:cccc:
$ tail -r zztt1.txt (10行ではなく全行表示)
12:0001:cccc:
11:0001:cccc:
10:0001:cccc:
9:0001:cccc:
8:0001:cccc:
7:0001:cccc:
6:0001:cccc:
5:0001:cccc:
4:0001:cccc:
3:0001:JJJJ:
2:0001:aaaa:
1:0001:zzzz:
$
$ cat block.txt --->1行100バイト+改行コード(¥n)で101行のデータ
0000000000:1234567890123(中略)78901234567890123456789012345678T
00001xxx00:1234567890123(中略)78901234567890123456789012345678T
00002xxx00:1234567890123(中略)78901234567890123456789012345678T
(中略)
00098xxx00:1234567890123(中略)78901234567890123456789012345678T
00099xxx00:1234567890123(中略)78901234567890123456789012345678T
00100xxx00:1234567890123(中略)78901234567890123456789012345678T
$ tail -b 1 block.txt
45678T
00096xxx00:1234567890123(中略)78901234567890123456789012345678T
00097xxx00:1234567890123(中略)78901234567890123456789012345678T
00098xxx00:1234567890123(中略)78901234567890123456789012345678T
00099xxx00:1234567890123(中略)78901234567890123456789012345678T
00100xxx00:1234567890123(中略)78901234567890123456789012345678T
$ tail -rb 1 block.txt
00100xxx00:1234567890123(中略)78901234567890123456789012345678T
00099xxx00:1234567890123(中略)78901234567890123456789012345678T
00098xxx00:1234567890123(中略)78901234567890123456789012345678T
00097xxx00:1234567890123(中略)78901234567890123456789012345678T
00096xxx00:1234567890123(中略)78901234567890123456789012345678T
45678T
$ tail -c 110 block.txt
2345678T
00100xxx00:1234567890123(中略)78901234567890123456789012345678T
$ tail -rc 110 block.txt
00100xxx00:1234567890123(中略)78901234567890123456789012345678T
2345678T
$
C:¥TEMP>%ADSH_OSCMD_DIR%¥tail -z
tail: illegal option -- z
usage: tail [-r] [-b number | -c number | -n number | -number] [file ...]