Linux:lessコマンドで複数ファイルを閲覧する方法

スポンサーリンク

lessコマンドで複数ファイルを閲覧する方法

lessコマンドで複数ファイルを閲覧するには引数に複数ファイルを指定します。

$ less README.md prompt.c prompt.h

マニュアルの説明

  :e [file]            Examine a new file.
  ^X^V                 Same as :e.
  :n                *  Examine the (N-th) next file from the command line.
  :p                *  Examine the (N-th) previous file from the command line.
  :x                *  Examine the first (or N-th) file from the command line.
  :d                   Delete the current file from the command line list.

複数ファイルを指定すると下部に表示している/全ファイル数が表示されます。

less-multiple1

:nキーを押すと次のファイルに、:pキーを押すと前のファイルに移動することができます。また、5:nキーのように押すと5つ先のファイル、😡キーを押すと先頭のファイルに移動することができます。

less-multiple2

:dキーを押すと閲覧対象から削除することができます。新しいファイルを追加したいときには:eに続けてファイル名を入力します。

less-multiple3

複数ファイルに対して検索を行いたいときは/に続けて*を入力することで検索できるようになります。