打包与压缩命令

打包命令tar,linux没有文件后缀,跟windows不同,为了区分好文件类型,要自己加

cvf的意思是创建文件,v显示哪些文件打包,f test.tar打包后的文件名,a.txt b.txt要打包的文件,打包意思是归档,不是压缩。

[root@localhost ~]# tar cvf test.tar a.txt b.txt

a.txt

b.txt

[root@localhost ~]# tar cf test.tar1 a.txt b.txt

 

要查看打包文件内有什么文件

[root@localhost ~]# tar -tf test.tar

a.txt

b.txt

 

解开打包文件xf

[root@localhost ~]# tar xf test.tar

[root@localhost ~]# ls

 

解压到/root/test/bar下

[root@localhost ~]# tar xf test.tar -C /root/test/bar

[root@localhost ~]#

 

压缩文件

[root@localhost ~]# gzip a.txt

解压缩

[root@localhost ~]# gunzip a.txt.gz

打包压缩到某个文件夹中

tar cf dabao.tar a.txt b.txt

gzip dabao.tar

也可以

tar cfz dabao1.tar.gz a.txt b.txt

tar cfjv dabao2.tar.bz2 a.txt b.txt

bzip2 a.txt

 

解压

[root@localhost ~]# tar xf dabao1.tar.gz -C /root/dabao

[root@localhost ~]#

 

压缩文件夹

tar cfz yasuo.tar.gz /etc/

[root@localhost ~]# tar  -tf yasuo.tar.gz |less

解压后带上etc,

[root@localhost ~]# mkdir congcong

[root@localhost ~]# tar xf yasuo.tar.bz2 -C /root/congcong

[root@localhost ~]# ls congcong

etc

[root@localhost ~]#

如果不想带etc,只要里面的文件

[root@localhost /]# cd /etc

[root@localhost etc]# tar czf dapigu.tar.gz *

[root@localhost /]# tar xf /etc/dapigu.tar.gz -C /congcong

[root@localhost /]# ls congcong

 

posted @ 2017-11-10 16:02  森森2017  阅读(837)  评论(0编辑  收藏  举报