Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
The less
command in Linux is a versatile and convenient text file viewer that allows you to view the contents of a file while providing advanced navigation features. In this tutorial, we'll cover basic usage examples and navigation shortcuts for the less
command.
less
:To open a file using less
, simply type less
followed by the file name:
less file_name.txt
Once a file is open in less
, you can use the following keyboard shortcuts to navigate through the file:
Up arrow
or k
: Move up by one lineDown arrow
or j
: Move down by one linePage Up
or b
: Move up by one pagePage Down
or Space
: Move down by one pageg
: Go to the beginning of the fileG
: Go to the end of the fileq
: Quit less
You can search for text within the file using the following shortcuts:
/search_term
: Search forward for the given search term?search_term
: Search backward for the given search termn
: Repeat the last search in the same directionN
: Repeat the last search in the opposite directionIf you are viewing a file that is being actively written to, such as a log file, you can use less
's follow mode to display new content as it is added:
F
while the file is open to enter follow modeCtrl + C
to exit follow modeYou can open multiple files with less
and navigate between them using the following commands:
Open multiple files:
less file1.txt file2.txt
Navigate between files:
:n
: Go to the next file:p
: Go to the previous fileTo display line numbers while viewing a file, press the -N
option:
less -N file_name.txt
In summary, the less
command is a powerful text file viewer in Linux that provides advanced navigation and search features. By understanding the basic usage examples and shortcuts, you can efficiently view and navigate through text files.
How to use less command in Linux:
The less
command is a pager that allows you to view and navigate through text files.
Example code:
less filename
Viewing file contents with less:
Use less
to open and view the contents of a file. Scroll using arrow keys.
Example code:
less filename
Navigating and searching within files using less:
Navigate through files using arrow keys. Search within files by typing /
followed by the search term.
Example code:
less filename
Press /
and type the search term.
Displaying line numbers and file information in less:
Show line numbers with the -N
option. Display file information with the -M
option.
Example code (with line numbers):
less -N filename
Example code (with file information):
less -M filename
Piping command output to less in Linux:
Pipe the output of a command to less
for easy navigation.
Example code:
command | less
Scrolling and paging through large files with less:
Scroll through files using arrow keys or use spacebar to page down. Press b
to page up.
Exiting and quitting less command in Linux:
Exit less
by pressing q
. Press Q
(Shift + q) to force quit without confirmation.
Setting options and customizing less behavior:
Customize less
behavior using command-line options. For example, set line-wrap with -S
.
Example code:
less -S filename