tar命令有以下选项
-c 创建一个压缩包
-x 解压缩一个压缩包
-j 解压缩bz2格式tar文件
-z 解压缩gz格式tar文件
-f 指定处理的文件名
-t 显示tar中的文件
-v 显示压缩/解压缩进度
一、压缩命令
对多个文件或者目录打包的时候,文件名后,在后面用空格隔开
tar 选项 压缩后文件名 文件一 文件二 ...
1、创建一个tar压缩包
[root@localhost test]# tar -cvf result.tar ~/file.txt ~/install.log
tar: Removing leading `/' from member namesA
/root/file.txt
/root/install.log
[root@localhost test]# ls
result.tar2、创建一个.tar.gz压缩包
[root@localhost test]# tar -czvf result.tar.gz ~/file.txt ~/install.log
tar: Removing leading `/' from member names
/root/file.txt
/root/install.log
[root@localhost test]# ls
result.tar result.tar.gz3、创建一个.tar.bz2压缩包
[root@localhost test]# tar -cjvf result.tar.bz2 ~/file.txt ~/install.log
tar: Removing leading `/' from member names
/root/file.txt
/root/install.log
[root@localhost test]# ls
result.tar result.tar.bz2 result.tar.gz二、解压缩命令
1、解压缩.tar压缩包
[root@localhost test]# tar -xvf result.tar
root/file.txt
root/install.log2、解压缩.tar.gz压缩包
[root@localhost test]# tar -zxvf result.tar.gz
root/file.txt
root/install.log3、解压缩.tar.bz2压缩包
[root@localhost test]# tar -jxvf result.tar.bz2
root/file.txt
root/install.log
三、查看压缩包内容
</pre><pre name="code" class="plain">[root@localhost test]# tar -tvf result.tar
-rw-r--r-- root/root 423 2014-09-20 05:13:00 root/file.txt
-rw-r--r-- root/root 29073 2014-02-24 14:24:54 root/install.log四、常见的gzip bzip2 zip文件压缩解压缩
.gz 压缩命令:gzip 解压:gunzip
.bz2 压缩命令:bzip2 解压:bunzip2
.zip 压缩命令:zip 解压:unzip

本文详细介绍了如何使用tar命令进行文件和目录的压缩与解压缩操作。包括创建不同格式的压缩包如.tar, .tar.gz, .tar.bz2,以及如何解压缩这些文件。此外还提供了查看压缩包内容的方法。
2495

被折叠的 条评论
为什么被折叠?



