「Linux系列」4-查询和解压缩
关键字:Linux学习路线、工具、常识、目录结构等
摘要:包含linux的学习路线和前要基础知识。
查询指令
1、find指令
| find /home -name hello.txt | 查找/home目录下的hello.txt文件 |
|---|---|
| find /home -user HL | 查找/home目录下用户名HL的所有文件 |
| find /home -size +200M | 查找/home目录下大于200M的文件(-小于) |
ls -l 查看的文件大小不直观,ls -lh则更好

2、locate指令
用于快速定位所查询文件的路径,基于数据库实现而非从根目录一个个查。
tips:查询前,需要#updatedb命令
| locate hello.txt | 快速定位hello.txt所在目录 |
|---|

3、grep指令
| cat /home/hello.txt | grep -n yes | 在hello.txt文件中查找yes所在行 |
|---|
- -n可以显示行号、-i可以忽略大小写。常常-ni组合使用!
- 符号 | 可以用来并行实现两个命令(管道命令)
- 但其实有没有双引号都可以 √(我喜欢不带,偷懒)

解压缩命令
1、gzip/gunzip指令
| gzip /home/hello.txt | 将hello.txt文件进行压缩 |
|---|---|
| gunzip /home/hello.txt.gz | 对压缩包进行解压 |

2、zip/unzip指令
| zip /home/hello.txt | 将hello.txt文件进行压缩 |
|---|---|
| unzip /home/hello.txt.gz | 对压缩包进行解压 |
| zip -r myhome.zip /home/ | 将home及其包含的文件压缩成myhome.zip |
| unzip -d box /home/myhome.zip | 将home/myhome.zip解压到box文件夹中 |

3、tar指令
| 配置命令 | 功能 |
|---|---|
| tar -zcvf pc.tar.gz /home/pig.txt /home/cat.txt | 将多个文件打包并压缩成animal.tar.gz |
| tar -zcvf mybox.tar.gz /home/box | 将box文件夹压缩成mybox .zip |
| tar -zcvf /home/mybox.zip | 将mybox.zip解压到当前目录 |
| mkdir /home/box1 tar -zxvf /home/mybox.zip -C /home/box1 | 将mybox.zip解压到/home/box1文件夹中 |

【附录】
![]()
HTML
Keep going,and keep trying...