Use the commands more less cat in Linux to view the contents of the file

  • 2021-01-14 07:42:14
  • OfStack

cat, more, less can be used to view the contents of the file; cat is a one-time display of the content of the entire file, but also can connect multiple files to display, it is often used with the redirection symbol, suitable for less file content; more and less1 are generally used to display the contents of files more than 1 screen, and provide the function of page turning. less is more powerful than more and provides commands to turn pages, jump, find, etc.

As we all know, cat, more, less can be used to view the contents of a file. The main differences are:

cat is one time to display the content of the entire file, but also can connect multiple files to display, it is often used with the redirection symbol, suitable for less file content;

more and less1 are generally used to display the contents of files more than 1 screen, and provide the function of page turning. more is more powerful than cat, providing paging display function, less is more powerful than more, providing page turn, jump, search and other commands. more and less both support: display the next page with space, b button to display the previous page. These three commands are described in detail below.

more file content or output view tool:

ES35en is one of our most commonly used tools. The most commonly used is to display the output content, and then page according to the size of the window, and then also can prompt the percentage of the file;

ES38en View File Content Tool:

less tool is also a document or other output for paging display tools, should be said to be the Linux orthodox view file content tools, extremely powerful; As you are a beginner, I recommend ES43en. Because the content of less is too much, we will introduce the most commonly used 1

Linux commands cat, more, less can be used to view the contents of the file; cat is a one-time display of the content of the entire file, but also can connect multiple files to display, it is often used with the redirection symbol, suitable for less file content; more and less1 are generally used to display the contents of files more than 1 screen, and provide the function of page turning. less is more powerful than more and provides commands to turn pages, jump, find, etc.

cat

The cat command displays the contents of the entire file from top to bottom on the screen.

1, command format

cat [选项]... [文件]...

2, command function

To output a [file] or standard input combination to standard output.

cat has three main functions:

1). Display the whole file at one time :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 commonly used parameters

-A, --show-all equals -vET -b, --number-nonblank Numbers non-empty output lines - e equals - vE -E, --show-ends displays "$" at the end of each line -n, --number Numbers all lines of output -s, --squeeze-blank does not print multiline blank lines -t is equivalent to -vT -T, --show-tabs will display the skip character as ^I -u (ignored) -v, --show-nonprinting uses ^ and M- citation, except for LFD and TAB help displays this help information and exits --version displays version information and exits

more

The more command will display the content one page at a time, which is easy for the user to read one page at a time. The basic command is to press the blank key (space) to display the content one page at a time, and press the b key to display the content one page at a time (back). It also has the function of searching for strings. The more command reads the file from front to back, so the entire file is loaded at startup.

1, command format

 more [-dlfpcsu] [-num] [+/pattern] [+linenum] [file ...] 

2, command function

more and cat both have the same function of viewing the contents of a file, but the difference is that more can view the contents of a file by page, and can also support the function of jumping directly to the line.

3. List of commonly used parameters

-Number of rows displayed at one time by num -d displays friendly prompts at the bottom of each screen -l ignores Ctrl+l (page break). If this option is not given, the more command pauses after displaying a line containing the Ctrl+l characters and waits for the command to be received. -f counts lines as actual lines, not as the number of lines after the wrap (some lines are too long to be expanded to two or more lines) - Clear the p screen before displaying the next one. -c clears the screen from the top and displays. - Contiguous blank lines in the s file are compressed into one blank line for display. -u does not show underscores +/ first searches for the string and then displays it from behind the string +num displays from line num

4. Common operation commands

Enter down the n row, need to be defined. Default is 1 line Ctrl+F Scroll down 1 screen Scroll the space bar down 1 screen Ctrl+B returns the previous screen = outputs the line number of the current row : f outputs the file name and line number of the current line v calls the vi editor ! The command calls Shell and executes the command q exit more

less

less tool is also a document or other output for paging display tools, should be said to be linux orthodox view file content tools, extremely powerful. less is more flexible in usage than more. In more, we have no way to turn to the front, can only look behind, but if the use of less, you can use [pageup] [pagedown] and other key functions to go back and forth to look at the file, more easily used to view the contents of a file! In addition, ES195en can have more search functions, not only can search down, can also search up.

1. Command format:

less [参数]  文件

2. Command functions:

less is similar to more, but with less you can browse through files at will, whereas more can only move forward, not backward, and less does not load the entire file before viewing.

3. Command parameters:

-b < Buffer size > Sets the size of the buffer -e automatically leaves when the file is displayed -f forces the opening of special files, such as peripheral codes, directories, and binary files -g flags only the last searched keywords -i ignores case when searching -m shows the percentage of commands similar to more -N displays the line number of each line -o < The file name > Save the output of less in the specified file -Q does not use warning sounds -s shows 1 row of consecutive null behavior - The S will be discarded if the line is too long -x < digital > Displays the "tab" key as the specified numeric space / String: The ability to search down for "string" The & # 63; String: The ability to search up for "string" n: Repeat the previous search (with/or ? The relevant) N: Reverse repeat the previous search (with/or ? The relevant) b Turn back 1 page d turns back half a page h displays the help screen Q exits the less command u Scroll forward half a page y Scroll forward 1 line The space bar scrolls 1 page Enter to scroll 1 line

For example, when we display the contents of /etc/profile, we have it display the line number;


[root@localhost ~]# less -N  /etc/profile

conclusion


Related articles: