Author's Foreword
Welcome little cuties to come and learn from my gtiee Qin Boss (qin-laoda) - Gitee.com
————————————————————————————————
Table of contents
A brief introduction to the command
——————————————————————————
Interstitial knowledge
There are some small mistakes in the last blog
1. rm -r is to delete a directory
2. The parameters of the command can be written consecutively or at the end, such as mv -i a.py ./b/b.py or mv a.py ./b/b.py -i
3. The default permission is generally designed to be 755
A brief introduction to the command
Immediately after the last blog, I briefly introduced ls (file information) pwd (view the absolute path of the current file) mkdir (create folder) touch (create file) cp mv rm chmod (modify permissions) and other related commands and and related parameters
Next, I will introduce other commands
Redirect command: >
ll > 文件路径
It can be seen that when redirection is used to write to the file, the running result is not displayed on the terminal, but written directly to the file, so only the contents of the file can be viewed
But when we write another result into it, we will find that the latter content covers the previous content
See if it's covered
If you want to add content, you can try >> this
ll >> 文件路径
Check if content is added
cat
View or merge file contents
view content
cat 文件名称
See if you can view the content. Cat is generally used for small files, and it is generally not recommended for large files.
Merge and view (that is, view the contents of multiple files)
cat 文件1 文件2
Create a linked file: ln
硬连接:ln 源文件 链接文件
软连接:ln -s 源文件 链接文件
Soft link:
Equivalent to creating a shortcut
Hard link:
How it looks on the desktop
The relationship between these two links and the source file, the modification of the source file will affect the two links, and the modification of the other two links will also affect the source file
What is the difference between the two?
We can see that there is one type of entry into the aa.py file, and there are two types of content into the b.py file and into the content of cc.py
aa.py is b.py, which can be understood as aa.py with b.py
What happens if the source file is deleted
It can be seen that the source file is deleted, the soft link is useless, but the hard link can still be used
Why did it cause such a result?
It is a bit like the address of Python. Deleting b.py is equivalent to disconnecting the pointing, that is, deleting the address pointing to this content
If there is a pointer that knows the C language, it can be understood very clearly
So the difference between hard links and soft links is here.
grep
Text search, grep allows pattern finding in text files. If matching data is found, grep prints all lines containing this data. Simply put, it matches the content of the text
grep "被查找的内容" 被查找的文件
It can be seen from the figure that the result returned by grep is to return only the lines with the searched content, and the lines that cannot be matched will be discarded.
-n Displays the matching line in the first line of the file content
grep "查找内容" 文件 -n
See if it shows up
-i ignore case
grep -i "匹配的内容" 文件
-v does not match related content
grep -i "匹配的内容" 文件
Can be understood as matching negation
There is another interesting command
ps aux| grep py
View the running py file and the running file containing py
wildcard
*:代表0个或多个任意字符
?:代表任意一个字符
[列举的字符]:代表的任意一个字符
find (find file name)
It is used to search for qualified files in a specific directory, and can also search for files owned by a specific user.
Writing:
find -name 文件名称或者某些标记
See if it matches a lot, that is, it matches the current directory, as long as it is in the current directory. No matter how many layers there are, it will match
tar
Pack and compress files
Packing: It is equivalent to folding clothes and putting them in boxes without changing the storage size
Compression: pack first and then compress, which is equivalent to putting a piece of clothing in a bag and venting the air, the clothes will become smaller and the storage size will change
Compression must be packaged, packaging is not necessarily compressed
We can roughly divide it into packing, compressing, unpacking, and decompressing
Pack
If we want to package, we only need to use the three parameters -c -v -f, remember that the f parameter must be written later
tar -cvf 打包文件名称 被打包的文件
If you dislike this method, you can use * to represent all files
unpack
tar -xf 打包文件名称
It can still be seen that this command is unpacked to the current directory
compression
Compression must be packed
tar -czf 文件名称.tar.gz 要压缩的文件
decompress
tar -xf 要解压的文件
This command is to unzip to the current directory
Unzip to the specified directory
-C Note that this C is uppercase
tar -xf 要解压的文件名称 -C 解压到指定目录
other compression methods
bz2
bz2
压缩: tar -jcvf 压缩包包名 文件
解压: tar -jxvf 压缩包包名
decompress
decompress
zip
zip
zip压缩的目标文件不需要指定扩展名,默认扩展名为zip。
压缩:zip 目标文件(没有扩展名) 源文件
解压:unzip -d 解压到的目标目录文件 压缩文件
compression
decompress
Decompression is a bit different here
When there is no -d parameter, it will be decompressed to the current directory by default.
Summarize:
This is the end of the above introduction. What we need to pay attention to is that the grep and find -name commands need to use strings, and the way of decompressing zip is somewhat different.