Previously you learned about the cat command to read a file from the terminal. Did you notice one thing that, it prints the entire file at once? In this way, you need to scroll up and down to inspect the entire file. What if you’re viewing a very large file? The cat command becomes tough to inspect the file. Here comes the Linux less command and a very similar more command. The less and more commands show the file contents one screen at a time, i.e. only the amount that fits your screen. You can then scroll the screen or find specific information. Even you can use regex to find content that matches your pattern! You’ll mostly use the less command over the more command. In this article, the following questions have been answered.
- What are the differences between the Linux less and more commands?
- Why is the less command better than the more command?
- A glance at the Linux more command
- Deep dive into the Linux less command
Table of Contents (Toggle to hide/view)
less command vs more command
‘more‘ came before ‘less‘ in Linux. So you can guess, ‘less‘ is an updated and upgraded version of ‘more‘. It has more functionality and flexibility than the ‘more‘ command. The main differences are:
- ‘more‘ loads the entire file in the memory and then shows it on the terminal. That’s why you can see the percentage showing at the bottom telling how much you’ve scrolled of the entire file.
- ‘less‘ loads one screen at a time in the memory instead of loading at once.
- When you reach the end of the result in more command, the command ends there. So you can’t perform any operation on it without running the command again.
- In less, the command doesn’t end until you hit ‘Q‘. So it’s helpful for inspection.
As you can see, the less command is better than the more command in memory efficiency, speed, usage, and inspection. That’s why you’ll mostly use ‘less‘. However, I’ll describe the basic operations of the more command so that you can play around.
Before you start
Download this dictionary from the internet and save it with the name dictionary.txt. You’ll use this file to play with the more and less commands.
$ mkdir MLwiki; cd MLwiki
~/MLwiki$ curl -L -o dictionary.txt 'https://tinyurl.com/zeyq9vc'
If the first line seems unfamiliar to you, try reading this blog on Organizing Files with mkdir, mv,cp.
The output should look like this:

Now try to read this file with the cat command you learned earlier.
$ cat dictionary.txt

Did you notice that within a fraction of a second the entire list has been printed? This is a very long list, and using the cat command, you can’t manipulate it that much. That’s why the Linux more and less commands come in handy.
more command in Linux
Now read the dictionary.txt file again but with the more command. Here’s the basic syntax for it:
$ more path/to/file
The syntax is the same as the cat command. But now without displaying the entire file at once, the more command is displaying one screen at a time. At the bottom line, you can see the percentage of the file that has been shown already.

Navigating with the more command
Use these commands to navigate through the file.
- [Enter key] – Scrolls down 1 line at a time
- [Space key] – Scrolls down 1 screen at a time
- [b] – Skips backward 1 screen at a time i.e. scrolls up 1 screen
- [f] – Skips 1 screen in forward. Equals to 2 space keys
- [=] – Shows current line number
- /pattern – Returns all occurrences that match this pattern. This is a regex
- dot (.) – Repeats the previous command
- [q] – Interrupt or exit
If you use the Linux more command, these are the shortcuts you’ll be using. There are lots of other options and shortcuts available, which you can see using the following commands. Note that both of the commands display different lists. You’ll also notice that the manual telling you to use the Linux less command.
$ more --help # a quick help
$ man more # more command manual
less command in Linux
As you’ve already known, the Linux less command is more useful than the more command. It sounds funny, doesn’t it? The less command is faster, memory efficient as it does not load the entire file while reading. So it’s your ultimate choice when reading and manipulating a large file. The less command has more flexibility, options, commands than more. Let’s dive deep into it!
Reading files with less
The basic syntax is:
$ less [option] path/to/file
To see the available options and commands of less, try both of these commands one by one.
$ man less
$ less --help
See how huge it is! That’s why you’re always being told to use the less command over the more command.
Now read the dictionary.txt file with less and manipulate it with the commands and options described below.
$ less MLwiki/dictionary.txt # From home directory
$ less dictionary.txt # If you're already in the MLwiki directory

Moving around with the less command
Use up, down, right, left arrow keys to move around one row or column at a time. To see the movement in columns, open another file where each line has multiple words. Use enter to scroll down one line, space to one screen at a time. These are just the basics, let’s see more in a table.
Command | Alternatives | Description |
---|---|---|
e | j, ^E, ^N, CR | Forward one line |
5e | Forward 5 lines | |
y | k, ^Y, ^K, ^P | Backward one line |
5y | Backward 5 lines | |
f | SPACE, ^F, ^V | Forward one window |
5f | Forward 5 windows | |
b | ^B, ESC-v | Backward one window |
5b | Backward 5 windows | |
d | ^D | Forward one half-window |
u | ^U | Backward one half-window |
RightArrow | ESC-) | Right one half screen width |
5RightArrow | Right 5 positions | |
LeftArrow | ESC-( | Left one half screen width |
5LeftArrow | Left 5 positions | |
^RightArrow | ESC-} | Right to the last column |
^LeftArrow | ESC-{ | Left to the first column |
UpArrow | Backward one line | |
5UpArrow | Backward 5 lines | |
DownArrow | Forward one line | |
5DownArrow | Forward 5 lines |
Key points to note here:
- The actual list is huge, so I’ve highlighted the commands that you’ll most likely use.
- The caret (^) indicates the Ctrl key. So ^E represents Ctrl+E, where E is just the key, not the uppercase letter.
- I used 5 before some commands just to show that you can use any number before these commands to scroll that amount of lines or screens.
- The default one-window is the terminal screen size you’re working on.
Searching with less command
You can either search for your desired word or use regex to find all the occurrences that match the pattern you’re looking for. The best part about searching with less command is that it highlights the matching part! To search for words that match boo, try this:
$ less dictionary.txt
/boo
Remember 2 things here:
- The pattern matches anywhere in a word. For example, this will also match Facebook.
- By default, this command will show only the matches on the displayed screen. To see the other matches, hit ENTER or SPACE.
Here’s a list of the searching commands:
Command | Description |
---|---|
/pattern | Search forward for matching line |
?pattern | Search backward for matching line |
&pattern | Display only matching lines, skip others |
n | repeat the previous search |
N | repeat previous search in the reverse direction |
= | filename, current line number, total lines, displayed size of the file, total size, percentage of the file displayed |
All of these commands are very important and very common. The last one seems the most important to me.
A search pattern may proceed by one or more of:
- ! or ^N – Search for NON-matching lines
- * or ^E – Search multiple files
- @ or ^F – Start search at first file (for ‘/’) or last file (for ‘?’)
Jumping with the less command
To jump over different positions in the file, use the commands listed below. But remember, you can use a number before any of these commands to multiply the command. For example, g is used to go to the first line of the file. So you can use 3g to go to the 3rd first line of the file.
Command | Alternatives | Description |
---|---|---|
g | <, ESC+< | Go to first line in file (or line N) |
G | >, ESC+> | Go to last line in file (or line N) |
p | % | Go to beginning of file (or N percent into file) |
t | Go to (N-th) next tag, if any | |
T | Go to (N-th) previous tag, if any | |
(, {, [ | Find close bracket ), }, ] | |
), }, ] | Find open bracket (, {, [ | |
m<letter> | Mark current position with <letter> | |
‘<letter> | Go to a previously marked position | |
” (2 single quotes) | Go to the previous position | |
^ | Beginning of the file (Predefined) | |
$ | End of the file (Predefined) |
2 things to notice here:
- The ‘find close bracket’ option finds a close bracket that matches the N-th open bracket in the top line (if any number is given). Otherwise finds a match for the previous open bracket.
- The ‘find open bracket’ option finds an open bracket that matches the N-th close bracket in the bottom line (if any number is given). Otherwise finds a match for the next close bracket.
Options in less command
The less command has a huge amount of options to choose from. All of them can be found in the manual. But here’s a few of them you might find useful in daily use.
- -a or –search-skip-screen
- Search skips current screen. Although you set this when opening the file with less command, it takes effect when you start searching for something.
- -A or SEARCH-SKIP-SCREEN
- The search starts just after the top line being displayed. Works the same as before.
- -e or -E
- Quit at end of the file. In less command, you might have noticed that even if you reach the end of the file, the command does not quit like in more command. But if you like to quit the command at the end, then use this option when opening the file.
- f or –force
- Force open non-regular file.
- F or –quit-if-one-screen
- Quit if the entire file fits on the first screen. If your file is so small that it fits the first screen, then what’s the meaning of trying the functionalities of less command? So then you may choose to use this option.
- g or –hilite-search
- Highlight only the first match for searches
- G or –HILITE-SEARCH
- Return the matches for searches, but don’t highlight them
- -m or –long-prompt
- Set the prompt style. By default, it shows the percentage of the file that has been displayed
- -n or –line-numbers
- Don’t use line numbers
Most important options
As the list of available options in the less command is huge, let’s see the most important ones in a different list.
- -? or –help
- Displays help from the command line.
- -i or –ignore-caseIf
- your search pattern doesn’t contain any uppercase later, then this option will ignore the case while searching for that pattern.
- I or –IGNORE-CASE
- Ignore case in all searches, whether it includes any uppercase or not
- -N
- Show line numbers
- -p [pattern]
- Starts showing the file from the given pattern
Conclusion
This was huge! Tried to cover the important ones that you might need. Still, a lot is remaining! If nothing described above matches your interest, try reading the less command manual. more and less commands in Linux are really fun to work with!
When working with the more and less commands, you might want to create and populate some files by yourself. To do so, try reading these blogs: