Posts Tagged ‘less’
When you want to see the contents of a text file in unix, the first two things to come to mind are
less. I choose
cat when the files are small, but the pagination and navigation in
less makes it the better choice most of the time.
Suppose you find a directory with five files that are unknown to you. Printing the contents of all five is easy enough with
cat and a pipe:
$ ls | xargs cat
But if you have five files, chances are you don’t just want everything scrolling past you. So we try:
$ ls | xargs less
Hmm … when you get to the bottom of
file1.txt we find the message
(END) - Next: file2.txt. What to do?
As always, the answer is in the
:n for next file,
:p for previous file.
Of course, this isn’t only useful when piping input into
less, it also works when specifying multiple arguments:
$ less file1.txt file2.txt file3.txt