网站建设资讯

NEWS

网站建设资讯

文件的归档和压缩-创新互联

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参数保留源文件)

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


标题名称:文件的归档和压缩-创新互联
当前路径:http://cdweb.net/article/jigcs.html