linux打包 压缩 解压tar常归操作

tar

打包 tar -cvf 打包后路径和文件名.tar 需要打包的路径和文件
压缩 tar -zcvf 打包后路径和文件名.tar.gz 需要打包的路径和文件
解压 tar -xvf 包名 -C 路径 (文件夹必

-c: 建立压缩档案
-v:显示所有过程
-f: 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名。
-x:解压
-z:有gzip属性的
-j:有bz2属性的
-C:指定解压路径

打包和打包压缩文件大写差别很大,例如:

1打包加压缩:将/etc下所有文件打包压缩到/tmp目录命名为 etc_backup.tar.gz

[root@oldboy ~]# tar -zcvf /tmp/etc_back.tar.gz /etc/ 
[root@oldboy ~]# ls -lh /tmp
total 9.0M
-rw-r--r-- 1 root root 9.0M Apr 15 15:02 etc_back.tar.gz

2.仅打包不压缩   

root@oldboy ~]#  tar -cvf /tmp/etc.tar /etc
[root@oldboy ~]# ls -lh /tmp
total 36M
-rw-r--r-- 1 root root 9.0M Apr 15 15:02 etc_back.tar.gz
-rw-r--r-- 1 root root  27M Apr 15 15:04 etc.tar

通过对比发现 压缩后9M,打包则为27M。

解压到指定目录

3.将/tmp/etc_back.tar.gz解压到 /root/tartest下

[root@oldboy ~]# tar -zxvf /tmp/etc_back.tar.gz -C /root/tartest/   (-C 大写 指定解压路径)
[root@oldboy ~]# du -h --max-depth=1 tartest/      (查看文件夹大小)
30M     tartest/etc
30M     tartest/

  

猜你喜欢

转载自www.cnblogs.com/homeboot/p/12705554.html