Friday, June 29, 2012

'less' Command

The navigation keys in 'less' command are similar to Vim editor. Let's look at few navigation commands.
 
Forward & backward pattern search
  • / - search for a pattern which will take you to the next occurrence
  • ? - search for a pattern which will take you to the previous occurrence
  • n - for next match in forward (using /) or backward direction (using ?)
  • N - for next match in backward (using /) or forward direction (using ?)
 
Screen navigation
  • j - navigate one line down
  • k - navigate one line up
  • h - navigate one character left
  • l - navigate one character right
  • w - navigate one word right
  • b - navigate one word left
  • G - End of file
  • g - Beginning of file
  • q - quit less pager
  • F - Simulate 'tail -f' inside less pager (this might come very handy, because when you open a file using less command, any content that is being appended will not be displayed automatically. Using 'F' command, we can tail the active file which is similar to 'tail -f'. By pressing [Ctrl+C], you will be back to the normal less pager)
  • [Ctrl + F] - forward one window
  • [Ctrl + B] - backward one window
  • [Ctrl + D] - forward half window
  • [Ctrl + U] - backward half window
  • [Ctrl + G] - show the current file name along with line, byte and percentage statistics
  • 10j - 10 lines forward
  • 10k - 10 lines backward
  • v - toggle between the vi editor back and forth
  • h - summary of less commands
  • &pattern - display only the matching lines, not all
 
Working with multiple files
 
Multiple files can be opened by passing file names as arguments as shown below:
 
# less file1 file2
 
While viewing file1, use :e to open another file as shown below:
 
# less file1
  :e file2
 
Navigate between the files using:
  • :n - go to the next file
  • :p - go to the previous file
 
[ Top ]

No comments: