tail
ファイルとディレクトリ
書き方
tail -f [file]ファイルの末尾を表示し、-f で見張り続けます。ログが切り替わった後も追うには -F が必要です。
よく使うオプション
| オプション | 意味 |
|---|---|
| -n | Print the last N lines |
| -n +N | Start at line N instead of counting from the end |
| -f | Keep printing as the file grows |
| -F | Follow by name and reopen the file after log rotation |
| -c | Print the last N bytes |
| -r | BSD: print the lines in reverse order (GNU uses tac) |
例
tail -f app.logWatches a log live; Ctrl-C stops.
tail -n +2 data.csvSkips the header line.
tail -F /var/log/nginx/access.logKeeps following after the log is rotated.
移したり消したり探したりするものです。聞き返してくれない命令が混ざっているので、-i を付ける癖が手を守ります。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. tail は何をしますか。
ファイルの末尾を表示し、-f で見張り続けます。ログが切り替わった後も追うには -F が必要です。
Q. どう打ちますか。
tail -f [file] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man tail にあります。このコマンドはファイルとディレクトリの仲間です。
関連するコマンド
man ページ: man tail