Less command in Linux is used to read the contents of a text file one page at a time at the terminal. It is useful for reading large text file because it accesses the file page by page rather than loading the complete file. This results in faster loading and the file can be browsed line by line or section by section.
- It allows users to navigate both forward and backward through the file.
In this tutorial, you will learn about
less command and uses of
less command with examples.
Syntax of less Command
less [options] filename
There are many options with
less command, you can find all options available with
less command using the command
Using the less filename command, The file’s first few lines are shown in the terminal. The file name and path are displayed in the bottom-left corner of the screen.
- You may have trouble figuring out how to exit less, press ‘q’ to exit from less.
- You may see empty blank lines at the top, if you try to display a short text file with less.
You can display the line numbers in the less command. Use
-N option with
less to show line numbers for the provided text file.
less -N filename
It may be a tough task to find any string or pattern in a large text file.
less command allows us to search for a specific piece of text. To find any string or pattern press
/ (forward_slash) to initiate a forward search and type whatever you want to find.
less forward slash
less pin filename
less command with multiple blank line file
less -s filename
less file1 file2
less multiple file accessing second file
less -x filename
less +F filename
sudo dmesg less
Linux command with examples
date | dd | df | diff | dir | dmidecode | du
echo | eject | env | exit | expr
grep | groups | gunzip | gzip
kill | kmod
man | mdsum | mkdir | more| mv
passwd | pidof | ping | pr | ps | pwd | pstree
rdiff-backup | reboot | rename | rm | rmdir
tac | tail | talk | tar | tee | time | tree | top | touch | tr
unalias | uname | uniq | unzip | uptime | users
vim | vi
yes | youtube-dl
zcmp | zdiff | zip | zz