This article takes CentOS7
this as an example.
Directory structure of this article
echo command
1 purpose
Output content to the console.
2 Basic grammar
2.1 Basic format
echo [选项] [输出内容]
2.2 Example
- Output environment variables
HOSTNAME
echo $HOSTNAME
- Output text content
Hello world
echo "Hello world "
head command
1 purpose
Displays the beginning of the file. By default, the first 10 lines of the file are displayed .
2 Basic grammar
2.1 Basic format
head [选项] [文件路径]
2.2 Common options
-n 行数N
View the content of N lines in the file header. N can be any number of lines.
head -n N [文件路径]
2.3 Example
View /etc/profile
the first 8 lines of
head -n 8 /etc/profile
tail command
1 purpose
Displays the tail content of the file. By default, the last 10 lines of the file are displayed .
2 Basic grammar
2.1 Basic format
tail [选项] [文件路径]
2.2 Common options
-n 行数N
: View the content of N lines in the file header. N can be any number of lines.
tail -n N [文件路径]
-f
: Track all updates to documents in real time.
tail -f [文件路径]
2.3 Example
View /etc/profile
the last 8 lines of
tail -n 8 /etc/profile
> and >> directives
1 purpose
>
The directive represents output redirection and will overwrite the file contents .>>
The instruction represents output append, the content is appended to the end of the file, and the file content will not be overwritten .
2 Basic grammar
2.1 Basic format
> [文件路径]
>> [文件路径]
2.2 Example
- Write
/home
directory listing contents to file/home/info.txt
(overwrite)
ls -l > /home/info.txt
- Append
/home
directory listing contents to/home/info.txt
end of file
ls -l >> /home/info.txt
- Overwrite
/home/test1.txt
file content with/home/test2.txt
file content
cat /home/test1.txt > /home/test2.txt
ln command
1 purpose
- Called a soft link or symbolic link, it mainly stores links to other file paths .
- Similar to Windows shortcuts.
2 Basic grammar
2.1 Basic format
ln -s [源文件路径] [软链接文件路径]
2.2 Example
/home
Create a soft link named under the directory tomyroot
link to/root
the directory
ln -s /root/ /home/myroot
- Delete the soft link
/home
named in the directorymyroot
(the same as removing the file)
rm /home/myroot
history command
1 purpose
- View historical commands that have been executed.
- You can also execute historical commands
2 Basic grammar
2.1 Basic format
history
2.2 Example
- Show all historical commands
history
- Show the last 5 historical instructions
history 5
- Execute historical instructions numbered 20
!20