1. less – A Paging Tool to View File Contents
Syntax: less filename
Description: You can press Enter or Page Up/Page Down to navigate through the pages. To exit when you reach the end of the content, press ‘q’.
[root@VM-8-13-centos ~]# less abc
hello world
hello world
abc(END)
2. more – View File Contents by Percentage
Syntax: more filename
[root@VM-8-13-centos ~]# more abc
3. head – View the First n Lines of a File (default n is 10)
Syntax: head filename
Description: If you want to view the first 15 lines instead of the default 10, how would you do that?
[root@VM-8-13-centos ~]# head -5 abc
You were my everything this goes out to someone that was
once the most important person in my life
i didn’t realize it at the time
i can’t forgive myself for the way i treated you so
i don’t really expect you to either
4. tail – View the Last n Lines of a File (default n is 10)
Syntax: tail filename
Description: If you want to view the last 5 lines of a file, similarly to head, use tail -5 filename
[root@VM-8-13-centos ~]# tail -5 a
At that time, I had no idea how I would wrong you
I really wanted to hold you
I really wanted you to understand me more than anyone else
You will always hold an important place in my heart
I will never believe that our love was just cut off like that.
Second usage of tail: Real-time view of newly added content in a file (real-time monitoring)
Syntax: tail -f filename
[root@VM-8-13-centos ~]# tail -f a
Application Scenario: Viewing server log files
Description: Linux is the operating system for servers, and the server will contain the code for the projects you are working on.
A project: is derived from the coding done by developers. If a bug occurs or it crashes while users are using it, how do developers troubleshoot the issue?
Developers will check their own code, which module the user was operating when the error occurred? Which function failed? What sequence of operations led to the error?
The server will generate a log file from the code written by developers, which records each user’s operational habits and points of operation, as well as very detailed error messages.
Specific Operation: Open two windows, the left side receives content in real-time, and the right side simulates user redirection to print content to the log file, while the left side receives in real-time.

Note:
In work, you need to ask developers what the log file for the module I am responsible for is called? Where is it located?
Generally, log files end with .log, for example: order.log
The purpose of testing the log file is to assist developers in locating the problem, improving work efficiency.
5. find – Search for Files and Print Paths
1. First method: Search by filename
Syntax: find path -name filename
Description: This path represents where to start searching. It indicates the range, and ultimately finds the absolute path related to this file.
If you start searching from the root directory, it is possible, but the efficiency is very low, equivalent to scanning the entire disk from the lowest level.
[root@VM-8-13-centos ~]# find /root -name mm
/root/a/b/c/d/mm
2. Second method: Search by file type
Syntax: find path -type type -name filename
File types: d represents directory, – represents regular file, l represents link file
Note: If you want to search for the path of a file by type, if the file is a regular file, you need to use “f”, and only in this case use f, at other times it is –
[root@VM-8-13-centos ~]# find ./ -type f -name mm
./a/b/c/d/mm
[root@VM-8-13-centos ~]# find ./ -type d -name mm
./a/b/c/mm
6. ln – Create a Link File
Description: A link file is like a shortcut to a source file, which points to the source file. It can be used to open and operate as a substitute for the source file.
Syntax: ln -s (must be an absolute path) linked filename (must be an absolute path) shortcut name
[root@VM-8-13-centos ~]# ln -s /root/supermarket/food/apple/fruit.txt /root/mm
[root@VM-8-13-centos ~]# ls
mm supermarket
[root@VM-8-13-centos ~]# ll
total 4
lrwxrwxrwx 1 root root 38 Mar 23 15:34 mm -> /root/supermarket/food/apple/fruit.txt
drwxr-xr-x 3 root root 4096 Mar 23 15:12 supermarket
7. Pipe Symbol |
Description: The pipe symbol connects two commands, taking the output of the previous command as the input for the next command. (The result of the previous command is a prerequisite for the next command)
Example: How to view lines 10-15 of the abc file?
Correct Answer:
head -15 abc | tail -6
Note: head -15 abc && tail -6 abc will yield two results, one is the first 15 lines and the other is the last 6 lines, which does not meet the requirement.
head -15 abc | tail -6 abc will still yield the last 6 lines of the entire abc file, which does not meet the requirement.
8. grep – Global Regular Expression Print (Filtering)
Syntax: output of a command | grep “keyword”
[root@VM-8-13-centos ~]# tail -10 abc | grep “害怕”
When we go out, I really fear letting you see
Description: What is the difference between && and |?
&& is a connector between two commands, where there is no logical relationship between the commands, only a sequential relationship.
While | pipe symbol means that the result of the previous command is needed as a condition for the next command, indicating a logical relationship.
9. wc – Count Characters
Syntax: wc filename parameters
Example: How many words are there in lines 10-15 of the abc file?
[root@VM-8-13-centos ~]# head -15 abc | tail -6 | wc -w
Parameters: -l: line count of the file
-w: word count of the file (word count is based on spaces or new lines in the file, not a character count)