标签:24 10 -- 压缩 解压缩 home txt root
gzip / gunzip
(1)基本语法
##将文件压缩为a.txt.gz 不保留原始文件a.txt
gzip a.txt
#解压a.txt.gz 得到文件a.txt 不保留压缩包a.txt.gz
gunzip a.txt.gz
(2)经验技巧
- 只能压缩文件,不能压缩目录
- 不保留原来的文件
- 同时压缩多个文件会产生多个压缩包
(3)案例实操
压缩
[root@VM-24-12-centos home]# gzip a.txt b.txt
[root@VM-24-12-centos home]# ll
-rw-r--r-- 1 root root 26 6月 10 16:51 a.txt.gz
-rw-r--r-- 1 root root 26 6月 10 16:51 b.txt.gz
解压
[root@VM-24-12-centos home]# gunzip a.txt.gz b.txt.gz
[root@VM-24-12-centos home]# ll
-rw-r--r-- 1 root root 0 6月 10 16:51 a.txt
-rw-r--r-- 1 root root 0 6月 10 16:51 b.txt
zip / unzip
(1)基本语法
zip [选项] xxx.zip 文件或路径
# -r:可选参数,用于递归内容,压缩目录时使用
unzip [选项] xxx.zip
# -d:可选参数,指定解压后文件的存放路径,不写则解压到当前路径
(2)经验技巧
- zip压缩命令在window/linux通用
- 会保留原始文件
(3)案例实操
压缩
[root@VM-24-12-centos home]# zip xxx.zip a.txt b.txt
adding: a.txt (stored 0%)
adding: b.txt (stored 0%)
[root@VM-24-12-centos home]# ll
-rw-r--r-- 1 root root 0 6月 10 16:51 a.txt
-rw-r--r-- 1 root root 0 6月 10 16:51 b.txt
-rw-r--r-- 1 root root 298 6月 10 16:56 xxx.zip
解压
[root@VM-24-12-centos home]# unzip xxx.zip -d /home/aaa
Archive: xxx.zip
extracting: /home/aaa/a.txt
extracting: /home/aaa/b.txt
[root@VM-24-12-centos home]# cd aaa
[root@VM-24-12-centos aaa]# ll
-rw-r--r-- 1 root root 0 6月 10 16:51 a.txt
-rw-r--r-- 1 root root 0 6月 10 16:51 b.txt
tar
(1)基本语法
tar [选项] xxx.tar.gz 文件或目录
# -c :打包
# -z :打包同时压缩
# -f :指定压缩后的文件名
# -x :解压
# -C :解压到指定目录,不指定解压目录时默认解压到当前文件夹
# -v :显示详细信息
(2)案例实操
压缩多个文件
[root@VM-24-12-centos home]# tar -czvf xxx.tar.gz a.txt b.txt
a.txt
b.txt
[root@VM-24-12-centos home]# ll
-rw-r--r-- 1 root root 0 6月 10 17:24 a.txt
-rw-r--r-- 1 root root 0 6月 10 17:24 b.txt
-rw-r--r-- 1 root root 117 6月 10 17:26 xxx.tar.gz
压缩目录
[root@VM-24-12-centos home]# tar -czvf xxx.tar.gz aaa/
aaa/
aaa/b.txt
aaa/a.txt
[root@VM-24-12-centos home]# ll
drwxr-xr-x 2 root root 4096 6月 10 16:59 aaa
-rw-r--r-- 1 root root 146 6月 10 17:28 xxx.tar.gz
解压
[root@VM-24-12-centos home]# tar -zxvf xxx.tar.gz -C /home/bbb
aaa/
aaa/b.txt
aaa/a.txt
[root@VM-24-12-centos home]# ll
drwxr-xr-x 3 root root 4096 6月 10 17:35 bbb
-rw-r--r-- 1 root root 146 6月 10 17:28 xxx.tar.gz
标签:24,10,--,压缩,解压缩,home,txt,root 来源: https://www.cnblogs.com/chyf1990/p/16364654.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。