tar :打包归档命令

打包:将一大堆文件或目录变成一个总的文件
压缩:将一个大的文件通过压缩算法变成一个小文件

-c :建立压缩档案
-x :解压
-t :查看内容
-r :行压缩归档文件末尾追加文件
-u :跟新源压缩包中的文件
-A :追加tar文件至归档
---------------以上只能用一个
-z :gzip
-j :bz2
-J :xz
-Z :compress
-v :显示过程
-o :文件解压到标准输出
-N :只将较指定日期更新的文件保存到备份文件
-f :使用档案名字   必选项,且放在选项的最后

示例:
1. tar -cvf :打包

[root@host test]# cp -r /tmp/* ./
[root@host test]# ll
总用量 6488
drwxr-xr-x. 2 root root      17 5月  13 11:40 test
-rwxr-xr-x. 1 root root 6639904 5月  13 11:40 vmlinuz-0-rescue-f18aae3c808945088363a05163c87df9
drwx------. 2 root root       6 5月  13 11:40 vmware-root_6376-1002617058
drwx------. 2 root root       6 5月  13 11:40 vmware-root_6385-1950294818
drwx------. 2 root root       6 5月  13 11:40 vmware-root_6561-1723274322
drwx------. 2 root root       6 5月  13 11:40 vmware-root_6587-1715213774
drwx------. 2 root root       6 5月  13 11:40 vmware-root_6602-1003206744
drwx------. 2 root root       6 5月  13 11:40 vmware-root_6617-1991582740
drwx------. 2 root root       6 5月  13 11:40 vmware-root_6622-960544717
drwx------. 2 root root       6 5月  13 11:40 vmware-root_6628-969129577
[root@host ~]# tar -cvf test.tar test
test/
test/.file1.swp
test/.file.swp
test/test/
test/test/kgc
test/vmlinuz-0-rescue-f18aae3c808945088363a05163c87df9
test/vmware-root_6376-1002617058/
test/vmware-root_6385-1950294818/
test/vmware-root_6561-1723274322/
test/vmware-root_6587-1715213774/
test/vmware-root_6602-1003206744/
test/vmware-root_6617-1991582740/
test/vmware-root_6622-960544717/
test/vmware-root_6628-969129577/
test/vmware-root_6640-994621948/
[root@host ~]# ll
drwxr-xr-x. 12 root root     4096 5月  13 11:40 test
-rw-r--r--.  1 root root 13322240 5月  13 11:41 test.tar
[root@host ~]# touch test/file
[root@host ~]# tar -uf test.tar  test
[root@host ~]# tar -tf test.tar
test/
test/.file1.swp
test/.file.swp
test/test/
test/test/kgc
test/vmlinuz-0-rescue-f18aae3c808945088363a05163c87df9
test/vmware-root_6376-1002617058/
test/vmware-root_6385-1950294818/
test/vmware-root_6561-1723274322/
test/vmware-root_6587-1715213774/
test/vmware-root_6602-1003206744/
test/vmware-root_6617-1991582740/
test/vmware-root_6622-960544717/
test/vmware-root_6628-969129577/
test/vmware-root_6640-994621948/
test/file

2. tar -zcvf :以gzip压缩

[root@host ~]# yum install gzip
[root@host ~]# tar -zcf test.gz test.tar
[root@host ~]# ll
drwxr-xr-x. 12 root root     4096 5月  13 11:43 test
-rw-r--r--.  1 root root 12469693 5月  13 11:46 test.gz
-rw-r--r--.  1 root root 13322240 5月  13 11:45 test.tar
#解压
[root@host ~]# mkdir jieya
[root@host testtar]# mv test.gz ./jieya/
[root@host testtar]# cd ./jieya/
[root@host jieya]# tar -xzvf test.gz
test.tar
[root@host jieya]# ll
总用量 25192
-rw-r--r--. 1 root root 12469693 5月  13 11:46 test.gz
-rw-r--r--. 1 root root 13322240 5月  13 11:45 test.tar

3. tar -jcvf :以bz2压缩

[root@host ~]# yum install bzip2
[root@host ~]# tar -jcvf test.bz2 test.tar
test.tar
[root@host ~]# ll
drwxr-xr-x.  2 root root        6 5月  13 11:55 jieya
drwxr-xr-x. 12 root root     4096 5月  13 11:43 test
-rw-r--r--.  1 root root 12594523 5月  13 11:54 test.bz2
-rw-r--r--.  1 root root 13322240 5月  13 11:45 test.tar
#解压:
[root@host ~]# rm -rf jieya/*
[root@host ~]# mv test.bz2 jieya/
[root@host ~]# cd jieya/
[root@host jieya]# tar -xjvf test.bz2
test.tar
[root@host jieya]# ll
-rw-r--r--. 1 root root 12594523 5月  13 11:54 test.bz2
-rw-r--r--. 1 root root 13322240 5月  13 11:45 test.tar

3. tar -Jcvf :以xz压缩

[root@host ~]# tar -Jcvf test.xz test.tar
test.tar
[root@host ~]# mv test.xz jieya/
[root@host ~]# cd jieya/
[root@host jieya]# ll
总用量 6080
-rw-r--r--. 1 root root 6222452 5月  13 11:59 test.xz
#解压:
[root@host jieya]# tar -Jxf test.xz
[root@host jieya]# ll
总用量 19092
-rw-r--r--. 1 root root 13322240 5月  13 11:45 test.tar
-rw-r--r--. 1 root root  6222452 5月  13 11:59 test.xz

------------------------------------------------------------------------------------------------------- 返回目

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值