Basic knowledge and commands of linux
- 1. Representation of different files
- 2. Basic operation of directories and files
-
- 2.1.ls (list) command
- 2.2. Wildcards
- 2.3 Aliases
- 2.4.du (disk usage) instruction
- 2.5. Create a new directory -mkdir
- 2.6. Create a new directory - touch
- 2.7. Three ways to create empty files
- 2.8. Create connection file -ln
- 2.9. Copy files or directories - cp
- 2.10. Delete files or directories - rm
- 2.11. Move file or directory -mv
- 2.13. The location of the linux command program - which
- 2.14.find Find files or directories finely
- 3. Summary
1. Representation of different files
d | Table of contents |
---|---|
- | normal file |
l | link file |
p | pipeline file |
s | socket |
c | character file |
b | block file |
1.1 Meaning of different file colors
- Black: normal files
- blue: folder
- azure: link file
- Green: executable files
- Red: compressed files
2. Basic operation of directories and files
2.1.ls (list) command
Format: ls [option] [file or directory...]
- Common options
-l | Display file and directory listings in long format ls -l=ll |
---|---|
-a | Display information about all subdirectories and files, including '.' and '...' |
-A | Basically similar to the -a option, the hidden directory will not display '.' and '...' |
-d | Show the properties of the directory itself instead of the contents of the directory |
-h | User-friendly display file directory and size, need to be used together with -l |
-R | Recursively display all contents of subdirectories and files |
2.2. Wildcards
- ? : match any character
- *: Match all non-hidden characters no matter how long or short, do not match hidden files at the beginning of '.'
- {1...10}: 1 to 10
- {a…z}: a to z
- {A…Z}: A to Z
- [0-9]: Matching number range
- \: escape character, expressing the original meaning
- 【^zhou】: match all characters in the list except characters
- 【123】: Take one of them to display, it doesn’t matter if there is none
2.3 Aliases
1.格式:alias 命令名=‘别名’
2.注意等式两边不能有空格,alias,临时修改,重启会失效,只有修改配置文件再回永久生效。
2.4.du (disk usage) instruction
1.统计指定目录或文件所占用磁盘空间大小
2.格式 :格式 【选项】【文件或目录....】
- common options;
of | Statistical catalog |
---|---|
you -a | Not only count the current directory, but also count all files in the current directory |
you h | Humanized statistics, humanized display of units |
you -sh | Only count the size of the space occupied by the current directory |
- Statistics file directory
- du -a: Not only counts the current directory, but also counts all files in the current directory
-
du -h: human statistics, showing units
-
du -sh: only count the space occupied by the current directory
- Note: -a and -s cannot be used at the same time
2.5. Create a new directory -mkdir
格式:mkdir 【选项】目录位置及名称...
要求:1.文件名最长255个字节
2.可以使用特殊字符,除了/和 空字符 ,一般不使用
- Create a folder bag under the current folder
- Create multiple folders under the current folder 111 222 333
- mkdir -p recursively create directories
Create aaa/bbb/ccc under the current folder
2.6. Create a new directory - touch
Function;
1. Can create a new file, and the size can be 0 bytes
2. Refresh time
3. Can create an empty file
4. Create an existing file, only realize the function of refreshing the file
- Create a file named passwd
- refresh time
2.7. Three ways to create empty files
touch 1.txt
vim 2.txt
echo‘ ’>3.txt
2.8. Create connection file -ln
Classification: Soft link (symbolic link) and hard link
Format: ln [-s] Source file or directory... Link file or target location plus -s is a soft link, no hard link
- Comparison of soft and hard links
A hard link is equivalent to backing up a copy and retaining all attributes. A
soft link is equivalent to creating a shortcut based on the source file
- Create a soft connection
2.9. Copy files or directories - cp
-r | This option must be used when copying a directory to recursively copy all files and subdirectories |
---|---|
-a | Keep all information intact |
-rm | delete file or directory -f force -i prompt -r recurse |
- Copying multiple files can only be copied to a directory or folder, not to a file directly, and this directory must exist
2.10. Delete files or directories - rm
格式:rm 【选项】要删除的文件或目录
-r | Force delete without reminder |
---|---|
-i | Remind user to confirm |
-r | delete entire directory recursively |
What should I do if the system space is too large and there is not enough space?
Answer: Delete large files
If you delete large files, is there still insufficient space?
Answer: Because there are other people who use this system again, it will not be released at this time
2.11. Move file or directory -mv
如果目标位置与源位置相同,则相当于执行重命名操作
格式: 【选项】...源文件目录...目标文件或目录
mobile directory
2.13. The location of the linux command program - which
格式:which 命令/程序名
find path
2.14.find Find files or directories finely
格式find【查找范围】【查找条件表达式】
-name | find by name |
---|---|
-size | Find by file size |
-user | Find by file attribute |
-type | Find by file type |
-name: search based on the name of the target file, wildcards are allowed
-size: search according to the size of the directory file, generally use "+" and "-" to set more than or less than the specified size as the search condition, the common unit kB (note k lowercase).MB.GB
**-type:**Search according to the type of the file, the type refers to the ordinary file (f), directory (d), block device (b), character device file (c), link (l) block device refers
to A device that reads data in blocks, multiple bytes are combined into a block of default 4K
- Find all subdirectories in the /boot directory
- usr: /home
-nouser is to find a folder without an owner, if lsi is deleted. The lisi folder becomes a folder without an owner
When using multiple conditions to search at the same time, you can use the logical operator
"-a" between the expressions to indicate that they are true at the same time.
"-o" indicates or or
Find all files in the /boot directory that are larger than 1MB and/or whose name starts with vm
3. Summary
Shell is a special program.
The classification, format and usage of Linux commands
Common Linux commands
View and switch directories (pwd, cd, Is, du)
Create directories and files (mkdir, touch, In)
Copy, delete, move directories and files (cp, rm, mv)
find directories and files (which, find)