tar
tar
description
tar 一个归档程序,可以对文件、目录进行归档,和压缩不一样的是,归档后文件变大。一般操作是对文件先归档后压缩,而tar命令同时集成压缩的命令,可以实现对归档文件进行压缩。
options
| 参数 | 参数说明 |
|---|---|
| -c | create a new archive(档案),归档,通常配合-v和-f使用,-cvf |
| -v | verbosely list files processed(详细列出已处理的文件) |
| -f | use archive file or device ARCHIVE |
| -x | --extract,提取 解档,通常配合-v和-f使用,-xvf,解档之后,原文件属性没有变化(文件创建时间等)。 |
| -C | 指定解档的位置 |
| -j | --bzip2 filter the archive through bzip2 归档的时候直接把归档文件使用bzip2压缩或解压缩 |
| -z | --gzip, --gunzip, --ungzip filter the archive through gzip,上同。 |
| --move-files | 归档后删除源文件 |
examples
tar -cvf guidang.tar testfile1 ip2.bz2 ip3.bz2 --remove-files
tar -cvf +归档的名称 +要归档的文件
[root@rhel tmp]# ll
-rw-r--r--. 1 root root 14 Mar 6 22:01 ip2.bz2
-rw-r--r--. 1 root root 14 Mar 6 22:01 ip3.bz2
-rw-r--r--. 1 root root 10485760 Mar 6 22:09 testfile1
[root@rhel tmp]# tar -cvf guidang.tar testfile1 ip2.bz2 ip3.bz2 --remove-files
testfile1
ip2.bz2
ip3.bz2
[root@rhel tmp]# ll
-rw-r--r--. 1 root root 11M Mar 7 18:41 guidang.tar //归档之后就一个文件了,--remove-files源文件就被删除。
tar -cvf test.tar test/* = tar -cvf test.tar test
把 test/下的所有文件进行归档
[root@rhel tmp]# ll test/
total 20484
-rw-r--r--. 1 root root 10485760 Mar 6 22:09 testfile2
-rw-r--r--. 1 root root 10485760 Mar 6 22:09 testfile3
-rw-r--r--. 1 root root 113 Mar 6 22:06 testfile.bz2
[root@rhel tmp]# tar -cvf test.tar test/*
test/
test/testfile2
test/testfile3
test/testfile.bz2
[root@rhel tmp]# ll -h
drwxr-xr-x. 2 root root 60 Mar 7 18:39 test
-rw-r--r--. 1 root root 21M Mar 7 18:46 test.tar
tar -xvf test.tar -C /tmp/1
[root@rhel tmp]# tar -xvf test.tar -C /tmp/1
test/testfile2
test/testfile3
test/testfile.bz2
[root@rhel tmp]# cd 1
[root@rhel 1]# ll -h
total 0
drwxr-xr-x. 2 root root 60 Mar 7 18:51 test
[root@rhel 1]# cd test/
[root@rhel test]#
[root@rhel test]# ll -h
total 21M
-rw-r--r--. 1 root root 10M Mar 6 22:09 testfile2
-rw-r--r--. 1 root root 10M Mar 6 22:09 testfile3
-rw-r--r--. 1 root root 113 Mar 6 22:06 testfile.bz2 //文件创建时间并没有发生改变。
tar -jcvf testduidang.tar.bz2 test
压缩,归档。
[root@rhel tmp]# tar -jcvf testguidang.tar.bz test
test/
test/testfile2
test/testfile3
test/testfile.bz2
[root@rhel tmp]# ll -h
drwxr-xr-x. 2 root root 60 Mar 7 18:39 test
-rw-r--r--. 1 root root 343 Mar 9 21:27 testguidang.tar.bz2
tar -jxvf ip.tar.bz2
解压缩,解档。
[root@rhel 1]# tar -jxvf ip.tar.bz2
ip.txt
ip2
test/
test/testfile2
test/testfile3
test/testfile.bz2
[root@rhel 1]# ll -h
total 12K
-rw-r--r--. 1 root root 36 Mar 9 22:17 ip2
-rw-r--r--. 1 root root 411 Mar 9 22:19 ip.tar.bz2
-rw-r--r--. 1 root root 36 Mar 8 18:09 ip.txt
drwxr-xr-x. 2 root root 60 Mar 7 18:39 test
man tar

浙公网安备 33010602011771号