Linux less command
The ‘less’ command is same as ‘more’ command but include some more features.
It automatically adjust with the width and height of the teminal window, while ‘more’ command cuts the content as the width of the terminal window get shorter.
Syntax:
Example:
Look at the above snapshot, we have given the command “less /var/log/udev”. In the left corner, name of the file is displayed.
Linux To Find A String
A particular string is searched by typing forward slash (/) and then followed by the string name, at place of file name in the lower left corner of the terminal box.
Syntax:
Example:
Look at the above snapshot, we want to find string ‘add’ hence we have typed “/add” at the lower left corner.
Output: Below snapshot, shows the output of command “/add”. The string ‘add’ will be automatically highlighted.
less Command Navigation Keys
The ‘less’ command have navigation keys similar to the ‘vim’ editor. Let’s have a look on some of the navigation keys and other operations of less command.
1. Search Navigation
search navigtion keys will help you in forward and backward search.
Forward search
- / : search for a pattern for the next occurence
- n : search for next match
- N : search for previous match
Backward search
- ? : search for a pattern for the next occurence
- n : for next match in backward direction
- N : for previous match in forward direction
Search path
Forward : //home/sssit/
Backward : /home/sssit
2. Screen Navigation
- Ctrl + f : forwards one window
- Ctrl + d : forwards half window
- Ctrl + b : backwards one window
- Ctrl + u : backwards half window
3. Line Navigation
to move forward or backward line by line
- j : forward by one line
- k : backward by one line
4. other Navigations
- G : used to go to end of the file
- g : used to go to start of the file
- q or ZZ : to exit
5. Count Keys
- 10j : 10 lines forward
- 10k : 10 lines backward
6. Marked Navigation
- ma : mark current position with letter ‘a’
- a : go to marked position
7. Multiple File
- by passing arguments in the same line
- while viewing file1 go to file2
to navigate between files when more then two files are opened
- n : go to next file
- p : go to previous file