文件的归档和压缩

tar命令

成都创新互联公司是一家集网站建设,崂山企业网站建设,崂山品牌网站建设,网站定制,崂山网站建设报价,网络营销,网络优化,崂山网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

作用:打包、压缩文件

[root@localhosttest]# tar --help

Usage: tar [OPTION...][FILE]...

GNU `tar' saves manyfiles together into a single tape or disk archive, and can

restore individualfiles from the archive.

 

Examples:

  tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.

  tar -tvf archive.tar         # List all files in archive.tarverbosely.

  tar -xf archive.tar          # Extract all files from archive.tar.

 

打包:

[root@localhost ~]# tarcvf grub2.tar  /boot/grub2/

# c  create 创建

#v  详细

#f  filename

 

[root@localhost ~]#file a.txt

a.txt: POSIX tararchive (GNU)

[root@localhost ~]#file /etc/passwd

/etc/passwd: ASCII text

 

file命令

作用:file  确定 filetype

用法:file /etc/passwd

注:linux系统不根据后缀名识别文件类型

用file命令查看文件的类型。

 

例:把两个目录或目标+文件打包成一个软件包

[root@localhost ~]# tarcvf ss.tar  /boot/  /etc/passwd

 

不解包,查看tar中的内容:

例:

[root@localhost ~]# tartvf ss.tar

 

 

解包:

[root@localhost ~]# tarxvf grub2.tar

指定解压路径:

[root@localhost ~]# tarxvf grub2.tar  -C /opt/

 

对比文件大小

[root@localhost ~]# du-sh /boot/grub2/

8.1M       /boot/grub2/

[root@localhost ~]# ll-h grub2.tar

-rw-r--r-- 1 root root7.7M Dec  3 20:41 grub2.tar

 

tar 归档+压缩:

格式(后缀名):.tar.gz  或   .tgz  

语法:tarzcvf newfile.tar.gz  SOURCE

 

[root@localhost ~]# tarzcvf grub2.tar.gz /boot/grub2/

对比大小

[root@localhost ~]# ll-h grub2.tar*

-rw-r--r-- 1 root root7.7M Dec  3 20:41 grub2.tar

-rw-r--r-- 1 root root3.1M Dec  3 21:02 grub2.tar.gz

 

解压:

[root@localhost ~]# tarzxvf grub2.tar.gz  -C /opt/

 

归档+压缩 :bz2

压缩:

[root@localhost ~]# tarjcvf grub2.tar.bz2  /boot/grub2/

格式(后缀名):.tar.bz2

语法:tar jcvf newfile.tar.bz2  SOURCE

 

对比大小

[root@localhost ~]# ll-h grub2.tar*

-rw-r--r-- 1 root root7.7M Dec  3 20:41 grub2.tar

-rw-r--r-- 1 root root2.5M Dec  3 21:08 grub2.tar.bz2

-rw-r--r-- 1 root root3.1M Dec  3 21:02 grub2.tar.gz

 

解压:  #tar -jxvfnewfile.tar.gz  -C /PATH/TO/DISTDIR/

[root@localhost ~]# tarjxvf grub2.tar.bz2  -C /opt/

 

zip软件包解压缩命令:

zip是压缩程序,unzip是解压程序。

压缩文件:

[root@localhost ~]# zippasswd.zip /etc/passwd

-r 压缩目录

[root@localhost ~]# zip-r grub2.zip /boot/grub2/

 

任务:Linux系统能不能解压rar压缩格式?能的话,如何解压?

 

解压

[root@localhost ~]#unzip grub2.zip  -d /opt/

 

补充:

压缩命令:gzip   bzip2  xz

语法格式:

gzip   文件

bzip2  文件

xz       文件

解压:

gzip -d  文件

bzip2 -d文件

xz    -d 文件   或unxz   文件

不解压的情况下查看内容分别用zcat 和 bzcat 、xzcat

 

特点:只能对文件进行压缩,且压缩后源文件消失(其中xz命令可以加上-k参数保留源文件)


分享名称:文件的归档和压缩
URL标题:http://ybzwz.com/article/gcdsjh.html