Linux file viewing command

1. cat command

1. cat+文件名, view the contents of the file:

For example, view the content of the main.c file:
insert image description here
2. cat < 文件名, write data to the file, Ctrl+d is to end the input

For example, write data to the file a.txt:
insert image description here
Check the content just written into a.txt:
insert image description here
3. cat 文件名1 文件名2 > 新文件名Merge the files, merge the contents of file 1 and file 2 into a new file

For example, merge the contents of a.txt and b.txt into file.txt:

insert image description here
Two, the more command

more 文件名, when the content of a file exceeds the number of lines that can be displayed on one screen, use more to display the file content in split screens. At this time, you can press Enter to display the remaining content line by line, or you can press Space to display the remaining content page by page content.

Three, less command

less 文件名, a text content viewer to view the file content, use the arrow keys to view the file content downwards, or use the arrow keys to view the file content upwards.

Fourth, the head command

head -n 文件名, display the contents of the first n lines of the file.

For example, to display the contents of the first three lines of the file file.txt:

insert image description here
5. The tail command
tail -n 文件名displays the contents of the last n lines of the file.

For example, to display the content of the last 3 lines of the file file.txt:

insert image description here

Guess you like

Origin blog.csdn.net/NuYoaH502329/article/details/132228586