温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

文件的归档和压缩

发布时间:2020-06-23 00:21:51 来源:网络 阅读:555 作者:Berton丶晓晓 栏目:大数据

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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI