Linux-Beginner Series_Part 1
File Management Commands - Directory
Opening the folder in the virtual machine will enter the graphical interface
Right click on the desktop
1. Create a file
grammar:
命令 空格 文件名.后缀
touch 文件名字
Example:
correct case
error demonstration
Use ls to view the directory
View the location of the above files in the graphical interface
2. Create a directory
grammar:
mkdir 空格 路径和目录名
Example:
View in GUI
Notice:
In the create directory, there is an option :
mkdir -p
// 指的是父系目录,也就是当创建目录没有上一级时,自动创建
see if it works
Common errors:
This will create 3 directories
Correct way:
3. copy
grammar:
命令 参数1 参数2
cp 源文件路径 目标文件夹
选项
cp -r 源目录 目标目录
Example:
If you want to put a folder into another folder, you need to use the option -r, if you don't use -r, you will be prompted to skip it.
-r写的位置,在源文件路径前或者目标路径后都可以:
cp -r eee aaa
cp eee aaa -r
Replenish:
The Tab key has the function of automatic completion
Example:
Here I want to automatically complete the huanghun folder, now directly Tab
4. Move
grammar:
命令 参数1 参数2
mv 源文件路径 目标文件路径
Example:
There is no need to type / under the independent folder
If you need to put it under the bbb folder in aaa, you need to write /
mv huanghun2.txt aaa mv huanghun2.txt aaa/ mv huanghun2.txt aaa/bbb
Check if the move was successful
5. delete
grammar:
rm -rf 文件或目录的路径
Example:
Delete the huanghun.txt file
delete fff folder
Notice:
rm -rf
This command will not be prompted, and it is agreed by default, even if it is a directory or the contents of the directory will be deleted together
Use with caution:
rm -rf /*
This command means: all files, all text and all lengths of the computer are cleared
不可以随便使用
。
Replenish
Create files, create directories, move, delete files that can be used by multiple files
6. View file content
This part uses instructions to view the contents of files, such as viewing files, scripts, and program contents, and use the following instructions to achieve:
cat全部
more翻页
head头部
tail尾部
grep过滤关键字
Example:
1. cat can view the entire content of the document
Under the graphics file, double-click to open it
Practice:
create a file
Double-click to open in the graphical interface, and write in any content
Use the command to view the file content in the terminal
2. more Turn the page to see more
at this time:
- Press enter to display one line at a time
- Press space to turn one page at a time
3. head head
view the header of the file
At this time, only 10 lines of the file are displayed, and the head command defaults to 10 lines
You can set:
4. Tail end
view the end of the file
The default is 10 lines of content, you can use - to see the content, such as -2
5. grep filter keywords
Mainly filter for file content
grammar:
grep 关键字 文件名
grep 'abc' /root/zhang.txt
The premise is that there must be abc in the file
7. Modify the file content
1. File editor
command vi, vim
编辑是i
退出是按ESC后 :wq保存退出
Example:
enter file
The document cannot be edited at this time, enter: i to enter the edit mode
Exit edit mode: press ESC and enter: wq
w is to save
q is to quit
2. Three modes of VI
Working mode: insert mode, command mode, visual mode, last line mode.
Just entered the file is the command line mode -->
Enter i to enter insert mode -->
Press ESC to enter the command line mode -->
Enter: wq to enter the last line mode
1. Command mode
In command line mode want to paste copy
- Enter the command yy to copy
- paste type p
2. :wq command
:wq is the last line mode command, not as the content of the file, it appears on the last line, indicating that it is saving and exiting.
:wq! It means to force save and exit.
3. How to switch between command mode and insert mode
- i esc
3. Command mode
Cursor positioning
- HJKL stands for up, down, left, right
- 0 at the beginning of the line $ at the end of the line
- gg header G footer
- 3G access to the third row
- /string (string means string, enter the character you want to find here) Press n N to search up and down.
Text Editor
- yy copy
- dd delete
- p paste
- u undo undo
enter other mode
-
a Enter insert mode (insert at the current cursor)
-
i enters insert mode
-
o Enter insert mode
-
A Enter insert mode
-
: Enter last line mode (extended command mode)
-
v enter visual mode
-
ESC returns to command mode
4. Extended command mode
save and exit
:w save
:q exit
:wq save and exit
find replace
: scope s/original content/new content/global
:1,3 s/aaa/111/g 从1-3行的aaa替换为111
:1,$ s/bbb/222/g 从1-结尾的bbb替换为222
read file/write file (save as)
:w 是 :write 写入的意思,默认是保存在自身的文件当中
:w zhang1.txt 当前zhang.txt另存为zhang1.txt
:quit means exit
set environment
:set nu 设置行号
:set nonu 取消设置行号
:set list 显示控制字符
8. Change directory
grammar:
cd change directory
pwd show current directory
Example:
cd to switch to the root directory
If a file with the same name appears when creating a file, the creation will fail