/ factorpad.com / tech / linux-essentials / less-command.html
An ad-free and cookie-free website.
Beginner
Learn to view text files at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux less command summary with examples (3:48)
Our fifth word, or command to memorize is less
from the category Text.
less
allows you to view and search
text files. In our last video we saw how the man command uses a text
viewer, or pager, to view user manual files. Well, that text viewing
program is less
.
-options | description |
---|---|
--help |
View a summary of less commands and navigation |
-N |
View line numbers |
If it helps, think of commands as mini programs and most have this
structure. First, type the
command
, second the
-option(s)
and third the
argument(s)
.
The less
command has over
30 options and its argument is typically the file you
intend to read. Many of
the options refer to scrolling and searching for patterns in text.
For now, we only have time to focus on two simple options.
First is --help
, which provides
a tidy screen showing scrolling options. Since there are many text
viewers and editors in Linux, I suggest sticking to, and learning,
only one or two.
Second is -N
, for viewing line
numbers.
So why is less
an important command?
Well, in many flavors of Linux, less is the default viewer for man
pages, and viewing text is an essential task in Linux.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows 10.
Here we go, let's start with less
--help
and then review this later.
Next, let's use less to view a file I created for this exercise, by
typing less
and the
filename video5.txt
. There it is.
Hit q
. Let's do something
different here. Type less -N
and the same file name video5.txt
.
See how it numbered the lines? This can be helpful, especially when
reviewing code. Hit q
again.
Okay now you know how to use less
.
And you know the syntax for commands, options and arguments.
One last tip about the less
command.
The footer of less -h
summary
reminds you of the two most important keys, h for help and q for quit.
Okay, thanks for visiting today. I hope this was a fun introduction
to the less
command.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
If you learned something please consider subscribing as a small token of appreciation. Every one helps get the word out about free learning.
man
command, hit
Back.pwd
,
click Next.
/ factorpad.com / tech / linux-essentials / less-command.html
A newly-updated free resource. Connect and refer a friend today.