dcsimg

Open Source Software Shortcuts for Doing More with 'Less'

By Juliet Kemp (Send Email)
Posted Aug 2, 2010


More on open source software

If you spend any time at all on the command line, you almost certainly use less (more's backward-scrollable cousin) on a very regular basis. Like me (until recently), however, you may never have taken the time to learn many of the long list of useful commands and shortcuts with which less is provided. Here are a few commands that will help you get more value out of less.

Command-line users are often well-acquainted with Less, More's backward-scrollable cousin. Here are a few not-so-well-known useful commands and shortcuts that may make Less even more valuable to you.

  • u and d: Scroll up (backward) or down (forward) half a screen, rather than the full screen provided by SPACE and b.
  • F: Keep scrolling forward, and keep trying to read whenever the end of the file is reached. This is especially useful when reading logfiles. It works like tail -f, but you can control when you read the next bit.
  • g and G: Go to the start or end of the file. Specify a number first to go to that line (e.g., 205G or 205g will go to line 205).
  • ma: Mark this position as "a". Use 'a to go back to the mark.
  • {}, [], (): If } appears on the bottom screen line, hit } to go forward to the matching bracket, and similarly with the other types of brackets. This works in reverse, too.
  • /pattern: Search forward for pattern. Use !pattern to search for non-matching lines, and ?pattern to search backward. Repeat the search with n (forward) or N (backward). Hit ESC-u to lose the highlighting.
  • :e filename: Load filename into less without closing and reopening.
  • ! command: invoke a shell to run the specified command. Refer to the current file with %.

If you want the full and gruesome details, be sure to check out the man page. Be warned, it's long!

Juliet Kemp has been messing around with Linux systems, for financial reward and otherwise, for about a decade. She is also the author of "Linux System Administration Recipes: A Problem-Solution Approach" (Apress, 2009).

Follow ServerWatch on Twitter

Page 1 of 1


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.