The difference between cat, more, and less commands in Linux

Source: Internet
Author: User
Tags word wrap

It is well known that Linux commands Cat, more, and less to view the contents of a file, the main differences are:
Cat is a one-time display of the entire content of the file, you can also connect a number of files to display, it is often used in conjunction with redirection symbols, applicable to the situation of less file content;
More and less is typically used to display content that has more than one screen of file content and provides the ability to turn pages. More powerful than cat, provides pagination display features, less than more powerful, provide page flipping, jump, find and other commands. And more and less support: Display the next page with a space, press B to display the previous page. These 3 commands are described in detail below.

Cat

[Plain]View PlainCopyprint?
  1. 1. Command format
  2. Cat [Options] ... [File] ...
  3. 2. Command function
  4. Output the [file] or standard input combination to the standard output.
  5. <strong>cat has three major functions:
  6. 1). show entire file at once: Cat filename
  7. 2). Create a file from the keyboard: cat > FileName can only create new files and cannot edit existing files.
  8. 3). Merge several files into one file: Cat file1 file2 > file</strong>
  9. 3. List of common parameters
  10. -A,--show-all equals-vet
  11. <strong>-B,--number-nonblank for non-null output line numbering </strong>
  12. -E equals-ve
  13. -E,--show-ends displays "$" at the end of each line
  14. <strong>-N,--number all line numbering for the output </strong>
  15. -S,--squeeze-blank does not output multiple lines of blank lines
  16. -T vs.-VT equivalence
  17. -T,--show-tabs to display the ^i character as a
  18. -U (ignored)
  19. -V,--show-nonprinting uses ^ and M-references, except LFD and TAB
  20. --HELP Display this help message and exit <strong>
  21. </strong>--version display version information and exit

4. Example

Number of non-null output lines

Output All line numbers:

More

The more command, which functions like cat, the Cat command is the entire contents of the file displayed on the screen from top to bottom. More will be a page-by-page display to facilitate users to read pages, and the most basic instruction is to press the blank key (space) on the next page, press the B key will be back to a page, but also the function of the search string. The more command reads the file backwards from the front, so it loads the entire file at startup.

[Plain]View PlainCopyprint?
  1. 1. Command format
  2. more [-DLFPCSU] [-num] [+/pattern] [+linenum] [File ...]
  3. 2. Command function
  4. The more commands and the cat function are the same view of the contents of the file, but the difference is that more can be viewed by the page to view the contents of the file, but also support the function of direct jump.
  5. 3. List of common parameters
  6. -num number of rows displayed at one time
  7. -D displays friendly tips at the bottom of each screen
  8. -L ignores Ctrl+l (page break). If this option is not given, the more command pauses the display after displaying a line containing ctrl+l characters and waits for the command to be received.
  9. -F Number of rows, in actual number of rows, rather than lines after word wrap (some single-line words that are too long will be extended to two or more lines)
  10. -P Displays the screen before the next screen.
  11. -C clear the screen from the top and then display.
  12. -s file is compressed into a blank line in a contiguous blank line.
  13. -U does not display underscores
  14. +/first searches for strings and then displays them from the string
  15. +num starting from Num line
[Plain]View PlainCopyprint?
    1. 4. Common Operation commands
[Plain]View PlainCopy print?
    1. Enter down n rows, which need to be defined. Default is 1 rows
    2. CTRL+F Scroll down one screen
    3. Space bar scroll down one screen
    4. Ctrl+b Back to previous screen
    5. = Output the line number of the current line
    6. : F output File name and line number of the current line
    7. V Call VI Editor
    8. command to invoke the shell and execute the command
    9. Q Exit More

Less

The less tool is also a tool for paging through files or other output, which is a very powerful tool for Linux to view the contents of a file. The usage of less is more resilient than more. In more, we have no way to turn front, can only look back, but if use less, you can use [PageUp] [PageDown] and other key functions to go to look at the file, more easily used to view the contents of a file! In addition, in less you can have more search function, not only to search down, but also to search upward.

[Plain]View PlainCopyprint?
  1. 1. Command format:
  2. Less [parameter] file
  3. 2. Command function:
  4. Less is similar to more, but you can browse files at will with less, and more can only move forward, but not backwards, and no will load the entire file before viewing it.
  5. 3. Command parameters:
  6. -B < buffer size > Set buffer size
  7. -e When the file display is finished, automatically leave
  8. -F forcing special files to be opened, such as peripheral code, directories, and binaries
  9. -G only flags the last keyword searched
  10. -I ignores case when searching
  11. -m shows a percentage similar to the more command
  12. <strong>-n Show line numbers for each line </strong>
  13. -o < file name > save less output in the specified file
  14. -Q does not use warning tones
  15. -S displays a row of continuous empty behavior
  16. -S line too long will be out of the partial discard
  17. -X < number > Displays the "tab" key as a specified number space
  18. <strong>/string: Search down the function of "string"
  19. String: Search up the function of "string" </strong>
  20. N: Repeat the previous search (with/or?). About
  21. N: Reverse repeats the previous search (and/or?) About
  22. <strong>b back one page
  23. D Turn back half page </strong>
  24. H Display Help interface
  25. Q Exit less command
  26. U scroll forward Half page
  27. Y Scrolls forward one line
  28. <strong> SPACEBAR Scrolls one page
  29. Enter a line </strong> scroll

Reference:

Http://www.cnblogs.com/peida/archive/2012/10/30/2746968.html

Http://www.cnblogs.com/peida/archive/2012/11/02/2750588.html

Http://www.cnblogs.com/peida/archive/2012/11/05/2754477.html

The difference between cat, more, and less commands in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.