1. Ubuntu 22.04.1 LTS の less のバージョン
現時点で、Ubuntu 22.04.1 LTS (WSL) に入っている less コマンドのバージョンを確認します。
$ /usr/bin/less -V
less 590 (GNU regular expressions)
Copyright (C) 1984-2021 Mark Nudelman
less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less
509 のようです。apt update
を実行したり、apt show less
なども確認しましたが、この Ubuntu ではこれが最新バージョンのようでした。
これは少し古いバージョンなので、最新バージョンをソースからインストールします。
2. less バージョン608 をインストールします
Downloading less を見ると、バージョン 608 が最新でしたので、これをインストールします。
(1) Downloading less から、less-608.tar.gz をダウンロードします。
(2) 適当なディレクトリ内で、このファイルを解凍します。
$ tar xvf less-608.tar.gz
(3) できあがった less-608 ディレクトリ内に移動します。
$ cd less-608
(4) ソースコードをコンパイルして、インストールします。
$ ./configure --prefix=/mnt/c/Users/foo/local/less-608
$ make
$ make install
--prefix
オプションを使い、インストール先を/mnt/c/Users/foo/local/less-608/
ディレクトリに指定しています。
以上の操作で、/mnt/c/Users/foo/local/less-608/
ディレクトリに less がインストールされました。
このディレクトリ内の構成は以下となっています。
$ tree ~/local/less-608/
/mnt/c/Users/foo/local/less-608/
|-- bin
| |-- less
| |-- lessecho
| `-- lesskey
`-- share
`-- man
`-- man1
|-- less.1
|-- lessecho.1
`-- lesskey.1
4 directories, 6 files
- less 以外に、lessecho と lesskey というコマンドがあり、share ディレクトリ内には、それぞれの マニュアルファイルが配置されています。
(5) バージョンを確認します。
$ ~/local/less-608/bin/less -V
less 608 (POSIX regular expressions)
Copyright (C) 1984-2022 Mark Nudelman
less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less
ちゃんと、「608」が表示されています。
(6) エイリアスを使い、インストールした less コマンドを「less」だけで呼び出せるようにします。
~/.bashrc
ファイルに以下を記述します。
if [ -f $HOME/local/less-608/bin/less ];then
alias less=$HOME/local/less-608/bin/less
fi
次回のログインから、less と書けば、今回インストールした less コマンドが使えます。
(7) less コマンドのマニュアルは、少し面倒ですが以下のコマンドで見ることができます。
$ man -l ~/local/less-608/share/man/man1/less.1
3. メモ
バージョン 598 (実際は593らしいです) から --header
オプションが使えるようになりました。このオプションを使うと、先頭行を固定したまま、それより下のコンテンツをスクロールすることができます。1行目がラベルになっているコンテンツを表示したい場合に便利です。(参考:Less version 598)