05tar命令详解
tar 命令用于对文件进行打包压缩或解压,格式为"tar [选项][文件]"。
在Linux 系统中,常见的文件格式比较多,其中主要使用的是 .tar 或者 .tar.gz 或者 tar.bz2格式,我们不用担心格式太多而记不住,其实这些格式大部分都是由 tar 命令来生成的。
1. 有且只能有一个的参数
-c 创建压缩文件
-x 解开压缩文件
-t 查看压缩包内有哪些文件
2. 可选参数
-z 用Gzip压缩或解压
-j 用 bzip2 压缩或解压
-v 显示压缩或解压过程
-f 目标文件名
-p 保留原始的权限与属性
-P 使用绝对路径来压缩(大写P)
-C 指定解压到的目录(大写C)
首先,-c 参数用于创建压缩文件, -x 参数用于解压文件,因此这两个参数不能同时使用。
其次,-z 参数指定使用 Gzip 格式来压缩或解压文件, -j 参数指定使用 bzip2 格式来压缩或解压文件。用户使用时根据文件的后缀决定使用 何种格式参数进行解压。
另外,对于 -v 参数,在执行某些压缩或者解压操作时,可能需要花费数个小时,如果屏幕一直没有输出,您一方面不好判断打包的进度情况,令一方面也会怀疑电脑死机了,因此非常推荐使用 -v 参数向用户不断显示压缩或解压的过程。
最后, -f 参数特别重要,它必须放到参数的最后一位,代表要压缩或解压的软件包名称。
[root@bogon 0608]# ls
560_file aaa.txt test
//1.打包(将test文件夹中的内容打包到test.tar包中,大小基本没变)
[root@bogon 0608]# tar -cvf test.tar test/
test/
test/560_file
test/aaa.txt
[root@bogon 0608]# ls -l
total 1146896
-rw-r--r--. 1 root root 587202560 Jun 8 09:38 560_file
-rw-r--r--. 1 root root 21 Jun 8 10:14 aaa.txt
drwxr-xr-x. 2 root root 37 Jun 8 11:09 test
-rw-r--r--. 1 root root 587212800 Jun 8 11:20 test.tar
//2.解包
[root@bogon 0608]# tar -xvf test.tar
test/
test/560_file
test/aaa.txt
[root@bogon 0608]# ls
560_file aaa.txt test test.tar
[root@bogon 0608]# ls -l
total 1146896
-rw-r--r--. 1 root root 587202560 Jun 8 09:38 560_file
-rw-r--r--. 1 root root 21 Jun 8 10:14 aaa.txt
drwxr-xr-x. 2 root root 37 Jun 8 11:09 test
-rw-r--r--. 1 root root 587212800 Jun 8 11:27 test.tar
[root@bogon 0608]# ls
//3.打包并使用Gzip压缩
[root@bogon 0608]# tar -czvf test.tar.gz ./test/
./test/
./test/560_file
./test/aaa.txt
[root@bogon 0608]# ls -l
total 574004
-rw-r--r--. 1 root root 587202560 Jun 8 09:38 560_file
-rw-r--r--. 1 root root 21 Jun 8 10:14 aaa.txt
drwxr-xr-x. 2 root root 37 Jun 8 11:09 test
-rw-r--r--. 1 root root 570109 Jun 8 11:36 test.tar.gz
//4.解压
[root@bogon 0608]# tar -xzvf test.tar.gz
./test/
./test/560_file
./test/aaa.txt
[root@bogon test]# ls -l
total 573444
-rw-r--r--. 1 root root 587202560 Jun 8 11:09 560_file
-rw-r--r--. 1 root root 21 Jun 8 11:09 aaa.txt
//5.打包并使用bzip2压缩
[root@bogon 0608]# tar -cjvf test.tar.bz2 ./test/
./test/
./test/560_file
./test/aaa.txt
[root@bogon 0608]# ls -l
total 574008
-rw-r--r--. 1 root root 587202560 Jun 8 09:38 560_file
-rw-r--r--. 1 root root 21 Jun 8 10:14 aaa.txt
drwxr-xr-x. 2 root root 37 Jun 8 11:09 test
-rw-r--r--. 1 root root 661 Jun 8 12:34 test.tar.bz2
-rw-r--r--. 1 root root 570109 Jun 8 11:36 test.tar.gz
//6.解压
[root@bogon 0608]# tar -xjvf test.tar.bz2
./test/
./test/560_file
./test/aaa.txt
[root@bogon test]# ls -l
total 573444
-rw-r--r--. 1 root root 587202560 Jun 8 11:09 560_file
-rw-r--r--. 1 root root 21 Jun 8 11:09 aaa.txt
//7.查看压缩包中的内容
[root@bogon 0608]# tar -tf test.tar.gz
./test/
./test/560_file
./test/aaa.txt
//8.解压到指定文件夹(使用-C参数)
[root@bogon 0608]# tar -xzvf teat.tar.gz -C /home/hk/
./test/
./test/560_file
./test/aaa.txt
[root@bogon 0608]# cd ..
[root@bogon hk]# ls
0607 0608 c test
05tar命令详解的更多相关文章
- Git初探--笔记整理和Git命令详解
几个重要的概念 首先先明确几个概念: WorkPlace : 工作区 Index: 暂存区 Repository: 本地仓库/版本库 Remote: 远程仓库 当在Remote(如Github)上面c ...
- linux yum命令详解
yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...
- Linux下ps命令详解 Linux下ps命令的详细使用方法
http://www.jb51.net/LINUXjishu/56578.html Linux下的ps命令比较常用 Linux下ps命令详解Linux上进程有5种状态:1. 运行(正在运行或在运行队列 ...
- Docker命令详解
Docker命令详解 最近学习Docker,将docker所有命令实验了一番,特整理如下: # docker --help Usage: docker [OPTIONS] COMMAND [arg ...
- linux awk命令详解
linux awk命令详解 简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分 ...
- android adb 命令详解
ADB (Android Debug Bridge) 是android SDK中的工具,需要先配置环境变量才能使用.起调试桥的作用,可以管理安卓设备.(也叫debug工具) ---------查看设 ...
- Git 常用命令详解
Git 是一个很强大的分布式版本管理工具,它不但适用于管理大型开源软件的源代码(如:linux kernel),管理私人的文档和源代码也有很多优势(如:wsi-lgame-pro) Git 的更多介绍 ...
- Top 命令详解
Top 命令详解 先感受一下top命令的执行结果吧!哈哈-- top - 17:32:34 up 3 days, 8:04, 5 users, load average: 0.09, 0.12, 0. ...
- Ruby Gem命令详解
转自:http://www.jianshu.com/p/728184da1699 Gem介绍: Gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如 http://rubygems.o ...
随机推荐
- Linux上传下载工具 lrzsz
- JS高级学习历程-3
JS-作用域链及作用 [作用域链] 1 什么事作用域链 一个变量,在当前环境可以使用,当前环境的内部环境也可以使用,内部的深层环境...也可以使用,变量在不同环境都可以使用的现象想成了一个链条,称为“ ...
- Linux —— shell认识与基础命令
shell 基础 shell路径: /etc/shells 系统shell版本: $SHELL 在父shell中可以调用子shell echo 把指定内容输出到屏幕上 操作选项: -e: 支持反斜杠控 ...
- Codeforces 185D(发现性质、欧拉定理)
学到的东西 不知道gcd时不妨先假设为d,然后为了满足全部式子说不定可以得到d的取值范围. 幂上带幂考虑欧拉定理的使用. 有几个特殊情况会破坏公式的完美不要紧,看看特殊情况是否能简便地判定. 连乘公式 ...
- CodeForces - 894A-QAQ(思维)
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tear ...
- php:php相关的函数或用法记录
//1:判断字符串是否全是字母组成的 $str = 'AAKAaa_aLJIGF'; var_dump(ctype_alpha($str)); //boolean false,全部是英文时才是返回tr ...
- python中“生成器”、“迭代器”、“闭包”、“装饰器”的深入理解
python中"生成器"."迭代器"."闭包"."装饰器"的深入理解 一.生成器 1.生成器定义:在python中,一边 ...
- Java中常见的坑
概述 Java是门极简风格的语言,比其它语言相比,它故意保持较少的特性,不仅在有些不常见的情况下会出些奇奇怪怪的错误,即使很一般的情况下也有可能让人栽根头.如果你习惯了别的语言,你读Java 的代码很 ...
- 点权生成树(gentree)
点权生成树(gentree) 题目背景 Awson是某国际学校信竞组的一只菜鸡.终于弄明白边权最小生成树后,然而又被大神嘲笑了.大神深邃的眼光中透露了些睿智,说道:“你会求点权最小生成树么?”Awso ...
- Json 后台转对象的方式或者获取属性值方式。
类似这类的 json字符串 后台转成 model 或者取其中一个属性值. 需要去掉前后引号 以及将转义字符去掉.空格代替 resoult = resoult.Substring(0, resoult. ...