less
ファイルとディレクトリ
書き方
less [file]ファイル全体を読み込まずに一画面ずつ見せます。/ で検索し q で抜けますが、more のように最後で自動的に閉じません。
よく使うオプション
| オプション | 意味 |
|---|---|
| -N | Show line numbers |
| -S | Chop long lines instead of wrapping them |
| -i | Ignore case while searching unless the pattern has capitals |
| -R | Pass color escape codes through as colors |
| +F | Start in follow mode, like tail -f |
| -X | Leave the output on screen after quitting |
| /word | Search forward; n repeats it, q quits less |
例
less +F /var/log/syslogFollows the log; Ctrl-C stops following and lets you scroll.
less -S wide.csvKeeps each record on one row so columns stay aligned.
git log | less -RPages colored output with the colors kept.
移したり消したり探したりするものです。聞き返してくれない命令が混ざっているので、-i を付ける癖が手を守ります。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. less は何をしますか。
ファイル全体を読み込まずに一画面ずつ見せます。/ で検索し q で抜けますが、more のように最後で自動的に閉じません。
Q. どう打ちますか。
less [file] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは7個です。全部は man less にあります。このコマンドはファイルとディレクトリの仲間です。
関連するコマンド
man ページ: man less