上犹电脑信息网我们一直在努力
您的位置:上犹电脑信息网 > 文件问题 > 快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)-tar文件怎

快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)-tar文件怎

作者:上犹日期:

返回目录:文件问题

快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)

linux启动界面

目录

1.文件和目录操作命令

2.用户和用户组操作命令

3.vim编辑器操作命令

4.打包和解压操作命令

5.系统操作命令

这是总的目录的,软件测试人员需要掌握的Linux命令会分成多个章节来写。

gzip 压缩

格式:gzip 文件名

1.压缩文件

[root@localhost test]# gzip services

快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)

使用这条命令,引起的变化:

1.文件的大小变了,从626K-125K

gzip可以对文件进行60%-70%的压缩

2.文件的名字改变了,从services 变成services.gz

其实就是在文件的名字后加上了.gz

原文件被删除,新增一个.gz的文件

压缩后文件格式变成.gz

gunzip 解压

格式:gunzip 文件名.gz

1.对.gz文件使用gunzip命令解压

[root@localhost test]# gunzip services.gz

gunzip变化与gzip相反

快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)

2.对.gz文件使用gzip -d 解压

[root@localhost test]# gzip services

[root@localhost test]# ls -lh services.gz

-rwxr-xr-x. 1 root root 125K Apr 14 17:55 services.gz

[root@localhost test]# gzip -d services.gz

[root@localhost test]# ls -hl services

-rwxr-xr-x. 1 root root 626K Apr 14 17:55 services

快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)

gzip压缩工具解压文件,gzip工具压缩率非常高,所以使用也非常频繁

tar 命令

打包和压缩:

打包是指将一大堆文件或目录变成一个总的文件

压缩则是将一个大的文件通过一些压缩算法变成一个小文件

这是二个步骤,是分开的

-c, --create 创建一个新归档

-x, --extract, --get 从归档中解出文件

-f, --file=ARCHIVE 使用归档文件或 ARCHIVE 设备

--force-local

即使归档文件存在副本还是把它认为是本地归档

-v, --verbose 详细地列出处理的文件

-z, --gzip, --gunzip, --ungzip 通过 gzip 过滤归档

0.归档文件,并创建一个新的归档文件

将123233和yum.conf打包在一起

[root@localhost test]# tar -cf 12.tar 123233 yum.conf

变化:

1.文件大小没变

[root@localhost test]# ls -hl 123233 12.tar yum.conf

-rw-r--r--. 1 501 test 9 4月 12 17:21 123233

-rw-r--r--. 1 root root 10K 4月 17 20:17 12.tar

-rwxrw-r--. 1 root root 969 4月 12 16:40 yum.conf

2.将二个文件生成一个.tar的文件

tar:在window来说就是将多个文件放到一个文件夹

3.将一个tar文件打开

[root@localhost test12]# tar -xvf 12.tar

4.在打包的同时并压缩--- -czvf(经常用)

[root@localhost test12]# tar -czvf qq.tar.gz 123233 yum.conf

-rw-r--r--. 1 root root 10240 4月 17 20:23 12.tar

-rw-r--r--. 1 root root 757 4月 17 20:30 qq.tar.gz

以上二个文件内容相同,第一个文件是将多个文件只 是打包在一起,第二个文件是将多个文件打包的同时并压缩

快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)

5.解包并解压

[root@localhost test12]# tar -xzvf q.tar.gz

快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)

tar命令打包并压缩:原文件没有被删除,而是生成一个新的.tar.gz

解压的时候也是将.tar.gz里的文件被释放出来,如果有相同的文件名被覆盖

打包压缩:tar -czvf 新文件名.tar.gz 文件1 文件2 ... 目录1 目录2...

解包解压:tar -xzvf 解包解压的文件名

6.将某个目录所有的文件和目录都打包压缩

[root@localhost test12]# tar -czvf test12.tar.gz *

zip 对文件或目录压缩

1.压缩文件

[root@localhost test]# zip q.zip 123233 yum.conf

对比gzip和zip压缩后的文件大小:

-rw-r--r--. 1 root root 757 4月 17 20:57 1.tar.gz

-rw-r--r--. 1 root root 891 4月 17 20:56 q.zip

可以得到gzip比zip压缩率高

2.压缩目录 -r

[root@localhost test]# zip -r test.zip test12

原目录与压缩后的文件

drwxrwxrwx. 3 root root 4096 4月 17 20:44 test12

-rw-r--r--. 1 root root 516448 4月 17 21:00 test.zip

压缩过程中原文件或原目录不会被删除

unzip 解压.zip文件

1.解压

[root@localhost test]# unzip test.zip

2.将解压的结果显示在屏幕上 -c

[root@localhost test]# unzip -c q.zip

将文件的内容直接展示在屏幕上

3.-n 解压时不要覆盖原有的文件

使用-n时,原有文件存在

[root@localhost test]# unzip -n q.zip

Archive: q.zip

使用-n时,原有文件不存在

[root@localhost test]# unzip -n q.zip

unzip解压后原来的.zip还存在

bzip2 压缩文件

格式:bzip2 文件名

1.bzip2压缩文件且原文件删除

[root@localhost test]# bzip2 yum.conf

并新生成了一个.bz2的文件

快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)

2.-k 压缩文件的同时保留原文件

[root@localhost test]# bzip2 -k services

快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)

bunzip2 解压

[root@localhost test]# bunzip2 123233.bz2

[root@localhost test]# ll

-rw-r--r--. 1 root root 9 4月 12 17:21 123233

生成一个新文件,原来的.bz2被删除了

快速高效学会Linux解压缩命令tar&gzip&gunzip等(必读四)

相关阅读

关键词不能为空
极力推荐

电脑蓝屏_电脑怎么了_win7问题_win10问题_设置问题_文件问题_上犹电脑信息网

关于我们