One place for hosting & domains

      How to Use the Less Command


      Updated by Nathan Melehan

      Written by Nathan Melehan


      Use promo code DOCS10 for $10 credit on a new account.

      What is Less?

      On Linux systems, less is a command that displays file contents or command output one page at a time in your terminal. less is most useful for viewing the content of large files or the results of commands that produce many lines of output. The content displayed by less can be navigated by entering keyboard shortcuts.

      Invoking Less

      To view the content of a file with less:

      less your-file-name
      

      To view the output of another command with less, redirect the output from that command using a pipe:

      ps -ef | less
      

      To see line numbers on each line, use the -N option:

      less -N your-file-name
      

      Keyboard Navigation in Less

      Use the following key commands to navigate through content viewed by less:

      Key commandAction
      down arrow key, enter, e, or jMove down one line.
      up arrow key, y, or kMove up one line.
      space barMove down one page.
      bMove up one page.
      right arrow keyScroll horizontally to the right.
      left arrow keyScroll horizontally to the left.
      gGo to the first line.
      GGo to the last line.
      10gGo to the 10th line. Enter a different number to go to other lines.
      50p or 50%Go to the line half-way through the output. Enter a different number to go to other percentage positions.
      /search termSearch forward from the current position for the search term string.
      ?search termSearch backward from the current position for the search term string.
      nWhen searching, go to the next occurrence.
      NWhen searching, go to the previous occurrence.
      m<c>Set a mark, which saves your current position. Enter a single character in place of <c> to label the mark with that character.
      '<c>Return to a mark, where <c> is the single character label for the mark. Note that ' is the single-quote.
      qQuit less

      Join our Community

      Find answers, ask questions, and help others.

      This guide is published under a CC BY-ND 4.0 license.



      Source link


      Leave a Comment