Low Orbit Flux Logo 2 F

Linux Command - less

The linux command less allows you to page through a text file.

This tool is similar to ‘more’ but it has a lot more features. It doesn’t need to read in an entire input file at one time so it starts faster with very large files when compared to other tools like vi.

There are more commands and options than what is shown here. We’re just covering the common / normally useful stuff. Multiple commands exist that do the same thing. There are many commands that behave in a very similar way. I’ve included a lot of redundant stuff but there exists a lot more in the man page.

Page through a file:



less /var/log/dpkg.log

Show line numbers:



less -N /var/log/dpkg.log

Searches will be case insensitive:



less -I /var/log/dpkg.log

Using a pipe:



ps -ef | less

Two files at once:



less /var/log/dpkg.log /var/log/boot.log

Commands

Commands can be proceeded by a number ( n ).

Common / Useful Commands

q quit
space scroll forward n lines ( window size )
enter scroll forward 1 line
up/down arrow up or down 1 line
left/right arrow scroll left or right
b scroll back n lines ( window size )
g go to first line
5g go to line 5
G End of file

Searching

/pattern search for pattern (regex)
/!pattern search for negated pattern
/?pattern search backwards

During a search:

n next match
N previous match
ESC-u turn on / off search highlighting
ESC-U turn on / off search highlighting and clear pattern
&/pattern only display matching lines ‘/’ added automatically

Extra Commands

You probably won’t ever use most of these.

f scroll forward n lines ( window size )
e scroll forward 1 line
j scroll forward 1 line
z scroll forward n lines ( window size ) ( change default n value if specfied )
d scroll forward n lines ( half screen size ) ( change default n value for d/u if specfied )
b scroll back n lines ( window size )
w scroll back n lines ( window size )( change default n value if specfied )
y k scroll back 1 line
u scroll back n lines ( half screen size ) ( change default n value for d/u if specfied )
J like j but keeps scrolling after end of file
K or Y like k but keeps scrolling after beginning of file
F scroll forward but keep reading at end of file ( kind of like “tail -F”)

Files:

:n examine next file
:p examine previous file
:x examine firest file
:d remove file from list

More:

= info about file, includes line number of bottom line
- apply a command line option while already running
same but for long option
v edit this line with an editor
s filename save to a file ( only when using piped input )

Matching and Jumping

m mark a line with whatever you single letter you type next ( displays when using -J )
M same but for last displayed line
ma mark line with ‘a’
‘a jump to line marked with ‘a’
’’ jump back
’^ jump to end of file
’$ jump to beginning of file

Options

-N display line numbers
-n suppress line
-J show status column
-i ignore case for searches
-I ignore case for searches even with uppercase pattern
-F exit at end of file
-Q silence the terminal bell
–save-marks save marks for another session