Command to view the contents of the file:
cat starts displaying the content from the first line and outputs all the contents
tac Displays the content in reverse order from the last line and outputs all the content
more Based on the window size, the actual file content is displayed page by page
less is similar to more, but has the advantage of being able to page forward and searching for characters
head. Only the first few lines of # are displayed.
##tail Only display the last few lines
nl Similar to cat -n, output the line number when displaying
tailf is similar to tail -f
##1.cat and taccat's function is to continuously add the contents of the file starting from the first line. The output is on the screen. However, cat is not commonly used. The reason is that when the file is large and the number of lines is relatively large, only part of the content can be seen when the screen cannot accommodate it all.
cat syntax: cat [-n] file name (-n: when displayed, output together with the line number)
The function of tac is to reverse the file starting from the last line and output the content data to the screen. We can find that tac is actually cat written in reverse. This command is also not commonly used.
tac syntax: tac file name.
2.more and less (commonly used)
The function of more is to convert files Starting from the first line, the file content is output appropriately according to the size of the output window. When the entire page cannot be output, you can use the "Enter key" to scroll down the line and the "Space bar" to scroll down the page. To exit the viewing page, please press the "q" key. In addition, more can also be used with the pipe character "|" (pipe), for example: ls -al | more
more's syntax: more file name
Enter goes down n lines, needs to be defined, the default is 1 line;
Ctrl f scrolls down one screen;
Space bar scrolls down one screen;
Ctrl b returns to the previous screen;
= Outputs the line number of the current line;
:f Output the file name and line number of the current line;
v Call the vi editor;
! command calls Shell and executes the command;
q exit more
The function of less is similar to that of more, but using more cannot turn pages forward, but can only turn pages backward.
less can use the [pageup] and [pagedown] keys to turn pages forward and backward, which seems more convenient.
less syntax: less file name
less also has a function to search for the content you want to find in the file, assuming If you want to check whether there is a weblogic string in the passwd file, you can do it like this:
[root@redhat etc]# less passwd
Then enter:
/weblogic
Enter
If there is For weblogic strings, Linux will display the characters in highlighted form.
To exit the viewing page, please press the "q" key.
3.head and tail
head and tail are usually used when only reading Use it to get the first few lines or the last few lines of the file. The function of head is to display the first few lines of the file
The syntax of head: head [n number] file name (number displays the number of lines)
The function of tail is just the opposite of head, only the last few lines of content are displayed The syntax of tail: tail [ -n number] File name ##4.nl nl functions and cat -n is the same, it also outputs the entire content from the first line and displays the line number nl syntax: nl file name 5.tailf For more Linux-related technical articles, please visit the Linux Tutorial column to learn!
The above is the detailed content of Command to view file contents under linux. For more information, please follow other related articles on the PHP Chinese website!