I'd like to know how to
and show it from the top instead of the end. Like the man command does.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
less, which will show the file from the top, allowing you to scroll through it, just like
If you're just interested in seeing the n first lines of a file,
head may be an alternative:
head -n 25 filename
will show the 25 first lines of the file.
Same thing for the n last lines of a file with
tail -n 25 filename
lessto make it even better:
I like to
alias m=less, so it's just a single-letter command, because I type it all the time. Putting a
|m at the end of anything pipes it into a pager.
You could put options like
-iMRj5X in the alias (e.g.
alias m='less -iMRX), but I do that with my
~/.lesskey file. (See
-i: searches are case-insensitive (unless you use any capital letters)
-M: longer status line, showing line number and file-percentage
-R: allow some control-codes through, so you can pipe colorized commands into less.
-X: don't switch to the terminal emulator's "alternate" screen, so whatever you were looking at will still be there when you
quit out of
less. (great for man pages after you find the option you want, and want to look at it while typing it.)
-j5: searches put the target line at row 5 instead of the top of the screen. So you can see context on both sides of your search result. (Sometimes I change this interactively, by typing
-j40or something inside
less, if it's most useful to see context before a search hit).
I also bind
prev-file, because the default bindings are two separate characters which are much slower to type:
This is my
$ cat .lesskey . next-file , prev-file #env LESS = iMRj5X
lesskey to "compile" it into a
This probably mattered more 20 years ago, but
less reads that binary file instead of parsing a text config file every time it starts.