The tool for viewing file content under linux is released!

Under Linux, we want to view the contents of a file. In addition to opening the file with an editor, Linux also provides several commands , which can output the contents of the file to the display screen for viewing without opening the file.

1、cat

The cat command is mainly used to view file content, create files, merge files, append files, etc.

1.1. View files

Command: cat file name
Description: This command will output all the contents of the file to the display.
cat -n filename: View the contents of the file and number each line.
cat -b file name: View the contents of the file, similar to -n, except that the blank lines are not numbered.
cat -s filename: When encountering consecutive blank lines, only output one blank line.
cat -e filename: Add a $ symbol after each line of output.

1.2. Create file

Command: cat > file name << file end mark Description: When creating a file, you must set the file end mark, and when the file content is written, you must enter the end mark you set.

Write the picture description here. If you want to add to the file, change ">" to ">>", where ">" means redirection, but the content must be cleared first, and ">>" means append.

1.3. Merge files

Command: cat file 1 file 2... >file
Description: Merge the files to be merged, such as file 1 and file 2, into the file again.

2. more and less

more:
The more command is similar to the cat command, but more does not display all the content on the display at one time, but displays it page by page for the convenience of readers. Press the space to turn the page down, press "Enter" to turn the page line by line, press "b" to turn the page up one page, "=" to output the current line number, and "q" to return to the command line. The more command reads files in front-to-back order, so the entire file is loaded at startup.
Command: more Parameter file name
Parameter (commonly used):
+n: display from line n.
-n: Define a page to display n lines
-c: Clear the screen from the top, and then display it again.

less:
less is also a tool for paged display of files or other output. Less is more powerful than more. Less provides functions such as [pageup][pagedown] to browse files back and forth, and there are more search functions in less. And less doesn't load the entire file before viewing it.
Command: less parameter file name
Parameters (commonly used):
-N: Display the line number
/string of each line: search down for "string".
? string: search up for "string"

3. head and tail

head: head is used to display the content of the first n lines, and the default n is 10.
Command: head parameter... file
parameter (commonly used):
-n: the number of lines to display from the beginning
-c: the number of bytes to display

tail:
tail is used for the content of the last n lines, n is 10 by default. tail can also specify a point to start writing the file to the standard output. Use the -f option of the tail command to display the content at the end of the file on the screen without refreshing.
Command: tail [required parameters][selection parameters] file
parameters (commonly used):
-n: number of displayed lines
-f: loop reading
-s: combined with -f, indicating that the time interval for each repetition is S seconds.

Guess you like

Origin blog.csdn.net/yaxuan88521/article/details/130281372