July 15, 2019
  • 2:01 pm 7 Ways to Learn Linux In a Structured Manner
  • 2:00 pm How to Mount DVDs and CD-Roms Using Ubuntu
  • 1:59 pm 5 Ways to Open a Terminal Console Window Using Ubuntu
  • 1:58 pm Operating Systems: Unix vs. Windows
  • 1:57 pm Popular Flight Simulators for Linux
Pearson Education (InformIT)

In this guide, you will find out whatever you need to understand about the Linux “less” command.

The “less” command is considered to be a more effective version of the “more” command which is utilized to display information to the terminal one page at a time.

A number of the switches are the exact same as the ones utilized with the more command however there are great deals of extra ones readily available also.

If you wish to check out a large text file it is much better to use the less command over an editor as it doesn’t load the entire thing into memory. It loads each page into memory a page at a time making it more efficient.

How To Use The Less Command
You can see any text file utilizing the less command simply by typing the following into a terminal window:

less
If there are more lines in the file than area on the screen then a single colon (:-RRB- will appear at the bottom and you will have a variety of alternatives to progress through the file.

The less command can likewise be utilized with output piped through another command.

For example:

ps -ef|less

The above command will show a list of running procedures one page at a time.

You can press either the space bar or the “f” secret to scroll forward.

Altering The Variety Of Lines That Are Scrolled Through
By default, the less command will scroll a single page at a time.

You can alter the number of lines that are scrolled when you press the space and “f” key by pushing the number right away before pressing the secret.

For instance, go into “10” followed by either the space or “f” key will cause the screen to scroll by 10 lines.

To make this the default you can go into the number followed by the “z” key.

For example, enter “10” and then press “z”. Now when you push the space or “f” essential the screen will constantly scroll by 10 lines.

A rather bizarre addition is the ability to press the escape crucial right away prior to the space bar. The impact of this is to continue scrolling even when you have reached the end of the output.

To scroll one line at a time press either the “return” secret, “e” or “j”. You can alter the default so that it scrolls a defined variety of lines by going into a number prior to the defined secrets. For instance, go into “5” followed by the “e” key will make the screen scroll 5 lines whenever “return”, “e” or “j” are pressed. If you inadvertently press an uppercase “J” the same result will take place except that if you struck the bottom of the output it will continue scrolling.

The “d” crucial allows you to scroll down a defined variety of lines. Again by entering a number before “d” will alter the default habits so that it scrolls the number of lines you specify.

To scroll back up the list you can use the “b” secret. Unlike the more command, this can work with both files and piped output. Going into a number prior to pressing the “b” key scrolls back up the defined number of lines. To make the “b” key completely scroll by the defined number of lines get in the number you wish to utilize followed by the “w” key.

The “y” and “k” keys work likewise to the “b” and “w” keys except the default isn’t to scroll one window at a time but one line at a time back up the screen. If you inadvertently push uppercase “K” or uppercase “Y” the outcome will be the exact same unless you struck the top of the output in which case the scrolling will continue beyond the start of the file.

The “u” key likewise scrolls back up the screen however the default is half the screen.

You can also scroll horizontally using the left and right arrow keys.

The ideal arrow scrolls half a screen to the right and the left arrow scrolls half a screen to the left. You can continue scrolling right over and over but you can only scroll left till you hit the start of the output.

Redisplay The Output
If you are viewing a log file or any other file that is continuously altering you may wish to refresh the information.

You can use a lowercase “r” to repaint the screen or an uppercase “R” to repaint the screen disposing of any output that has actually been buffered.

You can press an uppercase “F” to scroll forward. The advantage of utilizing the “F” is that when completion of the file is reached it will keep trying. If a log is updating whilst you are using the less command any brand-new entries will be displayed.

Move To A Specific Position In A File
If you want to return to the start of the output press lowercase “g” and to go to completion press uppercase “G”.

To go to a particular line get in a number before pushing the “g” or “G” secrets.

You can relocate to a position which is a specific portion through a file. Get in a number followed by the “p” or “%” secret. You can even go into decimal points since let’s face it, all of us require to go to place “36.6%” through a file.

Marking Positions In A File
You can set a marker in a file utilizing the “m” secret followed by any other lowercase letter. You can then return to the marker by utilizing the single quote “‘” essential followed by the same lowercase letter.

This implies you can specify a variety of different markers through the output which you can go back to quickly.

Searching For A Pattern
You can search for text within the output using the forward slash essential followed by the text you wish to browse or a regular expression.

For example/” hey there world” will find “hi world”.

If you wish to search back up the file you have to replace the forward slash with a question mark.

For example?” hey there world” will find “hello world” formerly output to the screen.

Load A New File Into The Output
If you have actually completed looking at a file you can load a new file into the less command by pressing the colon secret (:-RRB- followed by the “e” or “E” key and the path to a file.

For example “: e myfile.txt”.

How To Exit Less
To exit the less command press either the “q” or “Q” secrets.

Beneficial Command Line Switches
The following runtime switches might or may not be useful to you:

less -bN – The N means a number and loads the defined variety of kilobytes into memory. By default, the value is 64 kilobytes but you can define any number you want. If you go into -1 then the entire file will be loaded into memory which may or might not be an excellent concept depending upon the size of the file.
less -B – By default, the less command designates the required memory buffers by default when utilizing piped output. You can use the -B switch to avoid autobuffering.
less -c or less -C – By default the screen repaints by scrolling up the screen. To clear the screen from the top down use the -c or -C switches.
less -e – Triggers less to exit when it hits the end of the apply for the 2nd time
less -E – Causes less to leave when it hits completion of the declare the very first time
less -f – Open special files such as directories utilizing less
less -F – Causes less to exit if a file is less than one screens worth of data
less – g – Just highlight the last item found when browsing
less -G – Reduce highlighting entirely when searching
less -hN – Specify the optimum number of lines the less command can scroll back
less -i – Ignore case when browsing unless uppercase characters are found in the search pattern
less -I – Neglect case when searching
less -jN – The N stands for a number. This figures out where on the screen a line is placed when searched for. For instance, searching for “hello world” will position the line found with “hi world” in it on line 1 if less -j1 is utilized.
less -J – This shows a little asterisk in the left column (status column) which reveals when a piece of text which you have looked for has been discovered.
less -m – Displays the variety of bytes through a file rather of a colon at the bottom of the screen
less -M – Displays the line numbers of the output. For example “lines 1-23”
less -n – Suppress line numbers
less -N – Show line numbers on each line
less -o – This is used with piped output only. It outputs each page of the piped output to the file one page at a time. If the file exists it will ask whether you want to overwrite it.
less -O – This is the very same as -o except that it will not request for confirmation before overwriting a file.
less -p – This starts less at the very first occurrence of the pattern defined
less -P “text” – This replaces the message at the bottom of the screen to the text defined.
less -q – This prevents the bell from buzzing when you reach the end of the file. Other factors for the bell to ring such a void essential press stay.
less – Q – Reduces all noises
less -s – This condenses blank lines. For instance, if a file has 4 consecutive blank lines and you utilize the less -s command just 1 blank line will be displayed.
less -S – This causes long lines to be truncated instead of wrap them onto the next line
There is far more to the less command than you would anticipate. You can check out the full documentation by typing “guy less” into a terminal window or by reading this manual page for less.

An alternative to less and more is the tail command which shows the last couple of lines of a file.

finelinux

RELATED ARTICLES
LEAVE A COMMENT