Just like this question: I want to open a file with e.g., less -Sx32 file.dat
, but as I scroll down, keep the top line locked in place. How can I do this with less
?
2 Answers
It is now possible since less v600 (released on 2022-01-07)
With the --header
option, so in your case less --header 1 myfile
would keep the first line always displayed. Excerpt from the less v608
manpage:
--header
Sets the number of header lines and columns displayed on the screen. The value may be of the form "N,M" where N and M are integers, to set the header lines to N and the header columns to M, or it may be a single integer "N" which sets the header lines to N and the header columns to zero. When N is nonzero, the first N lines at the top of the screen are replaced with the first N lines of the file, regardless of what part of the file are being viewed. When M is nonzero, the characters displayed at the beginning of each line are replaced with the first M characters of the line, even if the rest of the line is scrolled horizontally.
Related: https://stackoverflow.com/a/71308346/1077650
How to install, configure and compile a new version of less
Get the latest RECOMMENDED version here and follow the instructions there.
# prerequisites on Debian 11.6 bullseye - see NB notes below
sudo apt install gcc make libncurses5-dev
download, configure, compile
wget http://greenwoodsoftware.com/less/less-608.tar.gz
tar xzvf less-608.tar.gz
cd less-608
sh configure
make
Then you can test it!
./less --version
./less --header 1 myfile
NB: in order to compile less
, you will need to have gcc
and make
packages installed.
NB: if configure failed
with something like Cannot find terminal libraries
, you need to install libncurses5-dev
package (or similar)
It requires some changes to less
. There exists an enhancement request here in GitHub. If it was implemented, you could use something like
less --freeze-pane 0,1 file.dat
to do what you want.

- 620
-Sx32
do? – jarno May 28 '20 at 09:06-S -x32
. – jarno Jun 06 '20 at 13:36