Use the Much less Command in Linux

by | Oct 9, 2023 | Etcetera | 0 comments

At its core, a lot much less command provides an interactive atmosphere to view the contents of a record, enabling consumers to scroll line-by-line or page-by-page. Now not like other equipment paying homage to cat, which simply dumps all of the record content material subject matter to the console, a lot much less promises easy navigation, search functionalities, and even offers choices like text highlighting.

In particular useful for peering into huge knowledge or logs, its efficiency and ease have rendered a lot much less an indispensable command for each and every novices and seasoned Linux execs.

Elementary syntax for a lot much less command:

$ a lot much less [FILE]
1. Display line numbers
a lot much less -N [file]

The -N chance signifies that you’ll be able to see line numbers throughout the output of the less command.

Example:

Whilst you execute a lot much less -N example.txt, the command a lot much less -N will open the record example.txt throughout the a lot much less pager with line numbers displayed firstly of each and every line. Right here’s a development output for what you may even see:

     1 This is line one of the most a very powerful record.
     2 Line two comes after line one.
     3 The third line is this one.
     4 And that is line 4.
     5 This example has 5 lines basically.
2. Search for text in a record
a lot much less -p [word] [filename]

This command helps you find a word or phrase in a record.

See also  Torque Social Hour: Kadence Launches A New AI Device

Example:

The command a lot much less -p apple fruit.txt would open the record fruit.txt and display the contents starting from the main occurrence of the word “apple.”

Let’s say the content material subject matter of fruit.txt is:

orange
banana
apple
grape
apple
cherry

Executing a lot much less -p apple fruit.txt would open the record in a pager starting from the street with the main occurrence of “apple,” appearing something like:

apple
grape
apple
cherry
3. Display a few knowledge
a lot much less [file1] [file2] [file3]

Use this command to open a few knowledge by the use of typing the input record names one at a time.

4. Reduce blank lines
a lot much less -s [filename]

This option reduces a chain of blanks lines and replaces them with a single blank line.

Example:

The output of the a lot much less -s file1.txt command will simply be the contents of file1.txt, on the other hand displayed one show at a time in your terminal, and with a few consecutive blank lines condensed into single blank lines.

Assume file1.txt accommodates the following:

This is line 1

This is line 3

This is line 5

This is line 7

For many who run a lot much less -s file1.txt, you might be able to see:

This is line 1

This is line 3

This is line 5

This is line 7
5. Keep content material subject matter in terminal after pass out
a lot much less -X [file]

By way of default, while you pass out a lot much less, the contents of the record might be removed from the show. To stick them on the show, use the -X chance.

Additional Linux directions:
Checklist Operations rmdir · cd · pwd · exa · ls
Document Operations cat · cp · dd · much less · contact · ln · rename · extra · head
Document Gadget Operations chown · mkfs · find
Networking ping · curl · wget · iptables · mtr
Search and Text Processing in finding · grep · sed · whatis · ripgrep · fd · tldr
Gadget Wisdom and Keep watch over env · historical past · most sensible · who · htop · glances · lsof
Particular person and Session Keep watch over display · su · sudo · open

The submit Use the Much less Command in Linux gave the impression first on Hongkiat.

See also  WP-Optimize Review: Database Cleaner & Speed Booster (2024)

WordPress Website Development

Supply: https://www.hongkiat.com/blog/linux-command-less/

[ continue ]

WordPress Maintenance Plans | WordPress Hosting

read more

0 Comments

Submit a Comment

DON'T LET YOUR WEBSITE GET DESTROYED BY HACKERS!

Get your FREE copy of our Cyber Security for WordPress® whitepaper.

You'll also get exclusive access to discounts that are only found at the bottom of our WP CyberSec whitepaper.

You have Successfully Subscribed!