Linux+: Linux Shell 17 – More or Less Commands

J

Jarret W. Buse

Guest
Linux+: Linux Shell 17 – More or Less Commands

There seems to be a need to view large amounts of information within a shell. Specifically, it is usually large files. The information can also be from the output of another command that more than fills the screen. In some cases, you can scroll back through the shell to see the output, but if the output is more than the shell cache holds, you cannot see it all.

The solution to the problem is to pipe the standard output to either the “more” or “less” command. The commands perform in a similar fashion, but do have differences.

The “more” command has the following syntax:

more options filename

The various options are as follows:

  • -# – specifies the number of lines for the screen size
  • -d – when a full page is displayed the user will be prompted with “[Press space to continue, 'q' to quit.]” and the message “[Press 'h' for instructions.]” when a key is pressed that has no function for “more”
  • -l – the characters '^L' is used as a form feed and causes “more” to pause. Using this option prevents the pause
  • -f – screen lines are not counted as multiples when an extra long line is wrapped to the next. Wrapping does not occur
  • -p – causes the display to clear and show the next page of text by not scrolling as is the default
  • -c – similar to -p, but does not clear the page. It simply rewrites each line and blanks the remainder of the line before going to the next line
  • -s – displays only only one blank line when multiple blank lines may exist
  • -u – prevent underlining
  • +/ - specifies a string to search for within the file
  • +# - start at the specified line number

Once the “more” command is displaying the information, there are keys which can be used to perform specific tasks as noted:

  • h or ? - shows help information for “more”
  • SPACE – displays next screen of information
  • z - displays next screen of information
  • ENTER – advances screen one line at a time
  • d – scroll set number of lines, default is 11
  • q – quits “more”
  • s – skip forward specified number of lines
  • f – skips forward a screen of text
  • b – skip back a screen
  • ' - goes to spot where search started
  • = - displays current line number
  • /pattern – searches for occurrence of pattern expression
  • !cmd or :!cmd – runs specified command (cmd) in a subshell
  • v – start editor at current line
  • CTRL+L – redraws screen
  • :f – shows current filename and line number
  • . - repeat previous command
The “less” command has a syntax of:

less options filename

The various options are as follows:

  • -? (--help) – shows help information for the “less” command
  • -a (--search-skip-screen) – performs a search starting at the beginning screen and searching towards the end of the display
  • -A (--SEARCH-SKIP-SCREEN) – causes the forward search to start at the current line
  • -bn (--buffers=n) – sets the buffer size in kilobytes for the current “less” command
  • -B (--auto-buffers) – buffer size is set automatically for the amount of data coming into “less”
  • -c (--clear-screen) – clears the screen from top to bottom before displaying the next screen of information
  • -d (--dumb) – suppresses error messages when shell terminal is dumb
  • -e (--quit-at-eof) - “less” ends the second time it reaches EOF or by pressing 'q'
  • -E (--QUIT-AT-EOF) - “less” ends the first time it reaches EOF or by pressing 'q'
  • -f (--force) – forces non-standard files to be opened, such as directories
  • -F (--quit-if-one-screen) – “less” will exit if the information fills one screen or less
  • -g (--hilite-search) – causes “less” to highlight the previous search, but only the particular string
  • -G (--HILITE-SEARCH) – suppresses highlighting of searched words
  • -hn (--max-back-scroll=n) – sets the maximum number of lines to scroll backwards
  • -i (--ignore-case) – causes the search to ignore case
  • -I (--IGNORE-CASE) – ignores case of search string even if it contains both upper and lower case letters
  • -jn (--jump-target=n) – sets the line number to set as the target line
  • -J (--status-column) – shows a status column to the left side of the screen
  • -m (--long-prompt) - “less” prompts verbosely with percentage of the display into the whole file
  • -M (--LONG-PROMPT) – causes more verbose prompts than -m
  • -n (--line-numbers) – suppresses line numbers
  • -N (--LINe-NUMBERS) – shows the line number at the beginning of each line
  • -Pprompt (--prompt=prompt) – specifies a personal prompt
  • -q (--quiet, --silent) – the bell is not sounded if user tries to pass the EOF
  • -Q (--QUIET, --SILENT) – the bell is never sounded
  • -s (--squeeze-blank-lines) – causes multiple blank lines to show only one blank line
  • -S (--chop-long-lines) – truncate lines which run past the screen width and not be wrapped to the next line
  • -u (--underline-special) – backspaces and carriage returns cause a visible character to be shown
  • -V (--version) – shows version of the “less” command

Some basic key commands used once the “less” command is running are as follows:

  • h – displays help information
  • SPACE, f, CTRL+v, CTRL+f – move forward one screen
  • ENTER – scrolls one line at a time
  • d – scrolls forward half a screen
  • b – scrolls backwards one screen
  • r – repaints the screen

This article covers the basic use of “more” and “less”. More information can be found in the “man” pages.

NOTE: “Less” has more features available than the “more” command because 'less is more'.
 

Attachments

  • slide.jpg
    slide.jpg
    49.4 KB · Views: 23,564

Members online


Top