[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedApril 12, 2023

How to use less command

How To Use Less Command

Less is a command line utility that displays the contents of a file or a command output, one page at a time. It is similar to more, but has more advanced features and allows you to navigate both forward and backward through the file.

When starting less doesn’t read the entire file which results in much faster load times compared to text editors like vim or nano .

The less command is mostly used for opening large files .

 

How to Use Less

The general syntax for the less program is as follows:

less [OPTIONS] filename

For example, to view the content of the /usr/share/common-licenses/GPL-3 file you would type:

less /usr/share/common-licenses/GPL-3

You can also redirect the output from a command to less using a pipe. For example, to view the output of the ps command page by page you would type:

ps aux | less

 

Navigating Through the File Content

When opening a file which content is too large to fit in one page, you will see a single colon (:).

To go forward to the next page press either the f key or Space bar. If you want to move down for a specific number of lines, type the number followed by the space or f key.

You can press either the Down arrow or Enter to scroll forward by one line and Up arrow scroll backward by one line.

To go back to the previous page hit the b key. Move up for a specific number of lines, by typing the number followed by the b key.

If you want to search for a pattern, type forward slash (/) followed by the pattern you want to search. Once you hit Enter less will search forward for matches. To search backwards use (?) followed by the search pattern.

When the end of the file is reached, the string (END) is shown at the bottom of the screen.

To quit less and go back to the command line press q.

 

Less Options

If you want less to shows line numbers launch the program with the -N option:

less -N filename

By default, when less exits, the file contents will be cleared from the screen. To leave file contents on screen, use the -X option:

less -X filename

The +F option tells less to watch the file contents for changes. This is useful when opening log files.

less +F /var/log/messages

When launched with +F, less will behave pretty much the same as tail -f .

 

Less Commands

The less program includes a number of commands that allows you to navigate through the file content and search for strings. To view a full list of all commands type h.

Most of the commands that you can enter from the keyboard are based on those used by both more and vi. The same action can be performed using different keys.

Below are some of the most frequently used commands to navigate through the file content when viewed by less:

Command

Action

Down arrow, Enter, e, or j

Move forward one line.

Up arrow,y or k

Move backward one line.

Space bar or f

Move Forward one page.

b

Move Backward one page.

/pattern

Search forward for matching patterns.

?pattern

Search backward for matching patterns.

n

Repeat previous search.

N

Repeat previous search in reverse direction.

g

Go to the first line in the file.

Ng

Go to the N-th line in the file.

G

Go to the last line in the file.

p

Go to the beginning of fthe ile.

Np

Go to N percent into file.

h

Display help.

q

Exit less.

 

Conclusion

By now you should have a good understanding of how to use the less command.

For a complete list of all options and commands type man less in your terminal.

Keep reading
How to use iptraf (Monitor NIC Traffic In Real Time) command
August 4, 2023

How to use iptraf (Monitor NIC Traffic In Real Time) command

How To Use Iptraf (Monitor NIC Traffic In Real Time) Command. IPTRAF is a command-line utility that allows users to monitor real-time network traffic on a Linux server. It can be used to monitor various network statistics such as TCP/UDP traffic, network bandwidth utilization, and network packet…

Read article
Guide to Monitoring Network Traffic on a Bonded Server.
August 4, 2023

Guide to Monitoring Network Traffic on a Bonded Server.

A Comprehensive Guide To Monitoring Network Traffic On A Bonded Server. Monitoring network traffic on servers is crucial for ensuring optimal performance, identifying potential issues, and ensuring network security. In this article, we will explore various methods to monitor network traffic…

Read article
How to Monitoring Network Bandwidth and Traffic on a Server.
August 2, 2023

How to Monitoring Network Bandwidth and Traffic on a Server.

How To Monitoring Network Bandwidth And Traffic On A Server. Monitoring network bandwidth and traffic on a server is crucial for maintaining optimal network performance and ensuring smooth operations. As servers handle incoming and outgoing data, understanding the flow of information and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00