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. Command format
- Cat [Options] ... [File] ...
- 2. Command function
- Output the [file] or standard input combination to the standard output.
- <strong>cat has three major functions:
- 1). show entire file at once: Cat filename
- 2). Create a file from the keyboard: cat > FileName can only create new files and cannot edit existing files.
- 3). Merge several files into one file: Cat file1 file2 > file</strong>
- 3. List of common parameters
- -A,--show-all equals-vet
- <strong>-B,--number-nonblank for non-null output line numbering </strong>
- -E equals-ve
- -E,--show-ends displays "$" at the end of each line
- <strong>-N,--number all line numbering for the output </strong>
- -S,--squeeze-blank does not output multiple lines of blank lines
- -T vs.-VT equivalence
- -T,--show-tabs to display the ^i character as a
- -U (ignored)
- -V,--show-nonprinting uses ^ and M-references, except LFD and TAB
- --HELP Display this help message and exit <strong>
- </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. Command format
- more [-DLFPCSU] [-num] [+/pattern] [+linenum] [File ...]
- 2. Command function
- 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.
- 3. List of common parameters
- -num number of rows displayed at one time
- -D displays friendly tips at the bottom of each screen
- -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.
- -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)
- -P Displays the screen before the next screen.
- -C clear the screen from the top and then display.
- -s file is compressed into a blank line in a contiguous blank line.
- -U does not display underscores
- +/first searches for strings and then displays them from the string
- +num starting from Num line
[Plain]View PlainCopyprint?
- 4. Common Operation commands
[Plain]View PlainCopy print?
- Enter down n rows, which need to be defined. Default is 1 rows
- CTRL+F Scroll down one screen
- Space bar scroll down one screen
- Ctrl+b Back to previous screen
- = Output the line number of the current line
- : F output File name and line number of the current line
- V Call VI Editor
- command to invoke the shell and execute the command
- 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. Command format:
- Less [parameter] file
- 2. Command function:
- 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.
- 3. Command parameters:
- -B < buffer size > Set buffer size
- -e When the file display is finished, automatically leave
- -F forcing special files to be opened, such as peripheral code, directories, and binaries
- -G only flags the last keyword searched
- -I ignores case when searching
- -m shows a percentage similar to the more command
- <strong>-n Show line numbers for each line </strong>
- -o < file name > save less output in the specified file
- -Q does not use warning tones
- -S displays a row of continuous empty behavior
- -S line too long will be out of the partial discard
- -X < number > Displays the "tab" key as a specified number space
- <strong>/string: Search down the function of "string"
- String: Search up the function of "string" </strong>
- N: Repeat the previous search (with/or?). About
- N: Reverse repeats the previous search (and/or?) About
- <strong>b back one page
- D Turn back half page </strong>
- H Display Help interface
- Q Exit less command
- U scroll forward Half page
- Y Scrolls forward one line
- <strong> SPACEBAR Scrolls one page
- 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