I just found out I can use less with multiple files. The less status line tells me:
(END) - Next: file2.txt
But how do I navigate previous/next from less?
I just found out I can use less with multiple files. The less status line tells me:
(END) - Next: file2.txt
But how do I navigate previous/next from less?
We read in the manpage:
:n Examine the next file (from the list of files given in the com‐
mand line). If a number N is specified, the N-th next file is
examined.
:p Examine the previous file in the command line list. If a number
N is specified, the N-th previous file is examined.
Found out from :h (help window) that I can use :p (for previous) and :n (for next)
Note: you actually have to type the : for these commands (even though there is a colon visible already).
:n jump to next file
:p jump to previous file
:x jump to first file
3:n jump 3 files ahead
3:p jump 3 files back
3:x jump to 3rd file
:f print current file name/info (helpful if you forget where you are)
Not strictly an answer for that question but maybe someone can find this useful nevertheless.
If the number of files is reasonably small, one could use vim for that:
vim -O files*
In this way all the files are displayed at once by splitting the screen automatically.
(Use -o to split horizontally.)
Some basic vim survival commands for this use case:
vim (!!!).I find the :n binding cumbersome, so I often use the more command instead. (The name less is a wordplay on more, after all.)
more just uses the space bar to advance to the next file, and prints a header before each one. Example:
$ more *.txt
::::::::::::::
a.txt
::::::::::::::
Example file A
::::::::::::::
b.txt
::::::::::::::
Example file B
--More--(Next file: c.txt)
For one line or really short files, I usually use grep . *.txt, because it will prefix each file with the file name:
$ grep . *.txt
a.txt:Example file A
b.txt:Example file B
c.txt:Example file C
Get help about navigation
While the less is opened press h key to open summary of less command and locate section CHANGING FILES:
CHANGING FILES
:e [file] Examine a new file.
^X^V Same as :e.
:n * Examine the (N-th) next file from the command line.
:p * Examine the (N-th) previous file from the command line.
:x * Examine the first (or N-th) file from the command line.
:d Delete the current file from the command line list.
= ^G :f Print current file name.
Commands marked with * may be preceded by a number, N.
For more detailed and verbose help run man less
How to open multiple files in less
# Name each file name as params
less file1.txt file2.txt file3.txt
Group of files sing wild character
less file.txt
less .txt
Examples of navigation
While the less is opened
Where I am
file.txt (file 1 of 7) (END) - Next: file1.txtChange by N-th file
Change to the N-th file
(file 4 of 7) so the 7th file is the last one, then use:Refresh the file
Open new file
Examine: file
file can be filename aka file4.txt or file name pattern aka *.txt or any path to the file(s) aka ~/file*.fileTABTAB loops files starting with file1.txt file2.txt file3.txt ...less in "secure" mode, ie the environment variable LESSSECURE is set to 1 or less is compiled in "secure" mode.Close file