Subscribe
Home Craft How to Use the less, more, and most Commands to Read Text Files in Linux

How to Use the less, more, and most Commands to Read Text Files in Linux

by Staff
0 comment

There are many GUI text editors available on a Linux system to view and modify text files. But you might just want to read your text files within the terminal. There are many commands available on Linux that allow you to do that, three of which are less, more, and most.


Read on to discover how you can use these three commands to effectively read text files on your Linux terminal.


What Is the less Command?

less is a Linux command used for filtering and viewing text files one screen page at a time. It is more advanced than the more and most commands.

With the less command, you can read really long text files in segments without having to load the whole file. It offers a lot of options and interactive features to make your experience more satisfying.

Because the less command outputs the first page of the text file and does not need to read the whole content of the file, it is faster than other text editors.

The less Command Syntax

The basic syntax of the less command is:

less [option] [name or location of the file]

How to Use the less Command

For this example, we will be using the sudo.conf file. The sudo.conf file is used to configure the sudo front end, and it has 139 lines. This file is present in almost every Linux-based operating system. You can also use any text file of your choice—as long as it has over 60 lines.

Using the Default less Command

The default less command prints out the first page of the file you use. Try it out with the sudo.conf file by executing this command in your terminal:

less /etc/sudo.conf

This prints out the first 53 lines of the document. To move forward a line at a time, press the Down key or Space.

To move backward by a line, press the Up key.

To move forward by a page, press B. To move forward several lines, hit B, then type the number of lines.

To move backward by a page, press D. To move backward by a number of lines, type D, then the number of lines you want to go back by.

Show Line Numbers With the less Command

You can also see the number of lines the file has as you view it. To do this, add the -N option when running the command. Try it out with the sudo.conf file by executing this command:

less -N /etc/sudo.conf

Search for Text Using the less Command

You can search for words and strings using the less command. When it finds the string, it will highlight the results in yellow.

Let’s search for the word: plugin. To do this, execute the default less command, and when it returns the output, type / and search for the word or string.

If you search for plugin, the output should look like this:

What Is the more Command?

The more command lets you view text files in your terminal one screen page at a time. This command works just like the less command but only with fewer functionalities.

The more Command Syntax

The basic syntax of the more command is:

more [option] [name or location of the file]

How to Use the more Command

The more command helps a user view portions of a large text file screen by screen in the terminal. You can use it to display text files and command outputs, search for a word in a file, and more.

Using the Default more Command

For this example, we will use the sudo.conf file found in the /etc folder. To use the more command to view a file, execute this command:

more /etc/sudo.conf

The result looks just like that of the less command. There is a difference though, at the bottom left of the screen you will notice that more displays the percentage of the text file, and that number increases or decreases as you move across the file.

Navigating the file with the more command is similar to the less command. You use the Enter key to move to the next line, D to move to a new page, and B to go back by one page.

Display the First N Lines of a File

Just like the head command in Linux, you can use more to view the first few parts of a file. This is the syntax:

more -N filename

To display the first five lines of the sudo.conf file, execute this command:

more -5 /etc/sudo.conf

What Is the most Command?

Just like the less and more commands, you can use most to read text files on Linux. It is not available in all Linux distributions by default, so you may have to install it yourself.

To check if it is installed, type most into your terminal. If it is not installed, your system will ask if you want to install it. Enter y to install. Alternatively, you can install the package using the default package manager on your machine.

The most Command Syntax

The basic syntax of the most command is:

most [option] [name or location of the file]

To get command-line help regarding the most command, check its manual page by running:

man most

How to Use the most Command

The most command works just like the less and more commands.

The Default most Command

The default most command prints out the first page of the text file. Try it out with:

more /etc/sudo.conf

The output is quite different from the less and more commands. At the bottom, there’s a blue line showing the name of the file and other helpful commands.

Using the less, more, and most Commands With Multiple Files

You can read multiple files at once using all of the above-stated commands. This is the syntax for each:

less filename1 filename2 filename3
more filename1 filename2 filename3
most filename1 filename2 filename3

Using less, more, and most With Other Commands

You can also direct the output of a command or a running process by using the pipe symbol alongside the less/more/most command. The pipe symbol redirects the output of one command as an input to another.

For instance, you could use less when checking the list of running processes on your operating system:

ps aux | less

Learn About Other Text Manipulation Commands on Linux

Just like the less, more, and most commands, Linux offers a lot of commands to help you view, manipulate, and process text files. Some of them include cat, echo, head, and tail. They all fulfill different purposes with their unique features.



Read the full article here

SaleBestseller No. 1
Apple AirPods Max Wireless Over-Ear Headphones. Active Noise Cancelling, Transparency Mode, Spatial Audio, Digital Crown for Volume Control. Bluetooth Headphones for iPhone - Green
Apple AirPods Max Wireless Over-Ear Headphones. Active Noise Cancelling, Transparency Mode, Spatial Audio, Digital Crown for Volume Control. Bluetooth Headphones for iPhone - Green
 Apple-designed dynamic driver provides high-fidelity audio; Active Noise Cancellation blocks outside noise, so you can immerse yourself in music
$449.99
SaleBestseller No. 3
Apple iPad Air 2, 64 GB, Space Gray (Renewed)
Apple iPad Air 2, 64 GB, Space Gray (Renewed)
Apple iOS 8; 9.7-Inch Retina Display; 2048x1536 Resolution; A8X Chip with 64-bit Architecture; M8 Motion Coprocessor
$129.99
SaleBestseller No. 4
2021 Apple 10.2-inch iPad (Wi-Fi, 64GB) - Silver
2021 Apple 10.2-inch iPad (Wi-Fi, 64GB) - Silver
Gorgeous 10.2-inch Retina display with True Tone; A13 Bionic chip with Neural Engine; 8MP Wide back camera, 12MP Ultra Wide front camera with Center Stage
$269.99
Bestseller No. 5
2022 Apple TV 4K Wi‑Fi with 64GB Storage (3rd Generation)
2022 Apple TV 4K Wi‑Fi with 64GB Storage (3rd Generation)
4K Dolby Vision and HDR10+ for vivid picture quality; Dolby Atmos for three-dimensional, theater-like sound
$123.49
Bestseller No. 7
Apple AirTag 4 Pack
Apple AirTag 4 Pack
Keep track of and find your items alongside friends and devices in the Find My app; Simple one-tap setup instantly connects AirTag with your iPhone or iPad
Bestseller No. 8
Apple MacBook Air with Intel Core i5, 1.6GHz, (13-inch, 4GB,128GB SSD) - Silver (Renewed)
Apple MacBook Air with Intel Core i5, 1.6GHz, (13-inch, 4GB,128GB SSD) - Silver (Renewed)
1.6 GHz dual-core Intel Core i5 (Turbo Boost up to 2.7 GHz) with 3 MB shared L3 cache; 13.3-Inch (diagonal) LED-backlit Glossy Widescreen Display, 1440 x 900 resolution
$305.00
Bestseller No. 9
Apple Of My Eye
Apple Of My Eye
Amazon Prime Video (Video on Demand); Amy Smart, Burt Reynolds, Liam McIntyre (Actors); Castille Landon (Director) - Castille Landon (Writer) - Dori A. Rath (Producer)
$3.99
SaleBestseller No. 10
Apple 35W Dual USB-C Port Compact Power Adapter ​​​​​​​
Apple 35W Dual USB-C Port Compact Power Adapter ​​​​​​​
The compact size and folding prongs make it easy to pack and store.; Charging cable sold separately.
$52.00

You may also like

Leave a Comment

Iman Hearts is one of the biggest lifestyle news and articles portals, we provide the latest news and articles about family, lifestyle, entertainment, and many more, follow us to get the latest news about what matters to you.

 

© 2022 Iman Hearts. All rights reserved. Sitemap