Linux study notes (8) -- File management (Part 2)

This article takes CentOS7this as an example.

Directory structure of this article

Linux study notes (8) -- File management (Part 2).png


echo command

1 purpose

Output content to the console.

2 Basic grammar
2.1 Basic format
echo [选项] [输出内容]
2.2 Example
  • Output environment variablesHOSTNAME
echo $HOSTNAME
  • Output text contentHello 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 行数NView the content of N lines in the file header. N can be any number of lines.
head -n N [文件路径]
2.3 Example

View /etc/profilethe 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/profilethe 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 /homedirectory listing contents to file /home/info.txt(overwrite)
ls -l > /home/info.txt
  • Append /homedirectory listing contents to /home/info.txtend of file
ls -l >> /home/info.txt
  • Overwrite /home/test1.txtfile content with /home/test2.txtfile 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
  • /homeCreate a soft link named under the directory to myrootlink to /rootthe directory
ln -s /root/ /home/myroot
  • Delete the soft link /homenamed in the directory myroot(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

Guess you like

Origin blog.csdn.net/qq_22255311/article/details/126211047