Linux Study Notes (7) -- File Management (Part 2)

This article takes CentOS7this as an example.

Directory structure of this article

Linux Study Notes (7) -- File Management (Part 2).png


cp command

1 purpose

Copy files to the specified directory.

2 Basic grammar
2.1 Basic format
cp [选项] [源文件路径] [目标路径]
2.2 Common options
  • -rCopy entire folder recursively
cp -r [源文件路径] [目标路径]
2.3 Supplementary instructions
  • For copying the entire folder, if you need to force non-overwriting , add another before the cp command.\
\cp -r [源文件路径] [目标路径]

rv command

1 purpose

Remove a file or directory.

2 Basic grammar
2.1 Basic format
rm [选项] [要删除文件或目录路径]
2.2 Common options
  • -rRecursively delete entire folders
rm -r [要删除文件或目录路径]
  • -fForced deletion without prompt
rm -f [要删除文件或目录路径]

mv command

1 purpose

Move or rename files and directories.

2 Basic grammar
2.1 Basic format
mv [文件路径] [新文件路径]
2.2 Example
  • 1 /home/test.txtrenametest1.txt
 mv /home/test.txt /home/test1.txt
  • 2 /home/test.txtMove to /rootthe directory
 mv /home/test.txt /root
  • 3 /home/test.txtMove to /rootthe directory and rename ittest1.txt
 mv /home/test.txt /root/test1.txt
3 Summary
  • Moving to the same folder directory is a renaming operation.
  • The move operation is performed in different file directories. If the file name is modified at the same time as the move, the rename operation is also performed.

more command

1 purpose

The more command is a text filter based on the VI editor, which displays the file content in full-screen mode on a page-by-page basis.

2 Basic grammar
2.1 Basic format
more [文件路径]
2.2 Example
  • 1 View /etc/profilefile content
more /etc/profile
2.3 Supplementary usage
  • The more command has many built-in shortcut keys (built-in commands), as follows
1. 空白键(space): 代表向下翻一页
2. Enter:代表向下翻一行
3. q : 代表退出more,不再显示该文件内容
4. Ctrl + F: 向下滚动一屏
5. Ctrl + B : 返回上一屏
6. =:输出当前行的行号
7. :f :输出文件名和当前行的行号

less command

1 purpose
  • Used to view file contents in split screen.
  • The function is similar to the more instruction, but more powerful.
  • Supports various display terminals.
  • When viewing the content of the file, this command loads the content according to the display needs instead of loading the entire file at once, which is more efficient for large files.
2 Basic grammar
2.1 Basic format
less [文件路径]
2.2 Supplementary usage
  • The less command has many built-in shortcut keys (built-in commands), as follows
1. 空白键(space): 代表向下翻一页
2. pageDown:代表向下翻一页
3. pageUp : 代表向上翻一页
4. /[字符串]: 代表向下搜索[字符串]内容;输入n:向下查找,输入N:向上查找。
5. ?[字符串] : 代表向上搜索[字符串]内容;输入n:向上查找,输入N:向下查找。
6. q:退出程序 

cat command

1 purpose
  • Used to view file contents, but cannot modify the file.
2 Basic grammar
2.1 Basic format
cat [选项] [文件路径]
2.2 Common options
  • -n: Display line number
cat -n [文件路径]
2.3 Example
  1. View /etc/profilefile contents and display line numbers
cat -n /etc/profile
  1. In order to facilitate viewing of files, you can add pipeline commands
cat -n /etc/profile | more

Guess you like

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