less

ファイルとディレクトリ

書き方

less [file]

ファイル全体を読み込まずに一画面ずつ見せます。/ で検索し q で抜けますが、more のように最後で自動的に閉じません。

よく使うオプション

オプション意味
-NShow line numbers
-SChop long lines instead of wrapping them
-iIgnore case while searching unless the pattern has capitals
-RPass color escape codes through as colors
+FStart in follow mode, like tail -f
-XLeave the output on screen after quitting
/wordSearch forward; n repeats it, q quits less

less +F /var/log/syslog

Follows the log; Ctrl-C stops following and lets you scroll.

less -S wide.csv

Keeps each record on one row so columns stay aligned.

git log | less -R

Pages colored output with the colors kept.

移したり消したり探したりするものです。聞き返してくれない命令が混ざっているので、-i を付ける癖が手を守ります。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. less は何をしますか。

ファイル全体を読み込まずに一画面ずつ見せます。/ で検索し q で抜けますが、more のように最後で自動的に閉じません。

Q. どう打ちますか。

less [file] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは7個です。全部は man less にあります。このコマンドはファイルとディレクトリの仲間です。

関連するコマンド

man ページ: man less