Tuesday, October 9, 2007

More context with less

less is a text file viewer. By default, it will print out one screenful of file contents at a time, and wait for you to tell it what to do next. Scroll forward? Backward? Search for a string?

Sometimes, when I scroll through an unfamiliar file, I don't know where I am in the file. Am I near the beginning, or the end? Am I in the middle?

To get some context, you can specify some run-time options for the less command.

#less -mN somefile.txt

-m will display the percentage complete at the bottom of the screen.
-N will display line numbers.

Instead of typing out the command-line options every time, you can specify the options in an environment variable.

#export LESS="-mN"

Finally, put the above command in your .bashrc file.

No comments: