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 ...
随机推荐
- python——类与对象
__init__ 方法: 1.Init 初始化方法的返回值必须是None. 3.类没有定义阶段,函数有定义阶段(不调用不执行). 实例化时触发__init__方法执行,为对象添加属性.[t1=stu ...
- 微信小程序之登录
微信小程序登录基本流程就是 1. wx.login获取js_code 根据app_id, secret, js_code 数据 wx.request 获取用户的openid和session_key ...
- Tomcat,Apache,JBoss的区别
1.Apache是Http服务器,Tomcat是web服务器,JBoss是应用服务器. 2.Apache解析静态的html文件:Tomcat可解析jsp动态页面.也可充当servlet容器. 详细内容 ...
- 安装redis服务器
安装redis服务器 Windows环境下安装: 第一步:下载压缩包(地址:https://github.com/MicrosoftArchive/redis/releases) 第二步:解压并打开 ...
- JS代码运行延迟
还是上篇文章的项目. 现在是屏幕上需要显示九张图表,刚好用一张3X3的表格来显示.但是负责这块内容的同事始终没法让九张图表同时显示,有些图表的位置空了出来. 大家百思不得其解,最后只得求助技术经理. ...
- 自动化测试资源(二):火狐浏览器驱动 geckodriver
geckodriver:https://github.com/mozilla/geckodriver geckodriver 历史版本下载列表:https://github.com/mozilla/g ...
- 简易的开发框架(微服务) Asp.Net Core 2.0
Asp.Net Core 2.0 + Mysql Orm + Ioc + Redis + AOP + RabbitMQ + Etcd + Autofac + Swagger 基础框架: https ...
- 《java学习三》jvm性能优化-------调优
常见参数配置 -XX:+PrintGC 每次触发GC的时候打印相关日志 -XX:+UseSerialGC 串行回收 -XX:+PrintGCDetails 更详细的GC日志 -X ...
- 高效的设计可视化UI
http://www.uimaker.com/uimakerdown/uitutorial/35990.html http://maqetta.org/downloads/ .Data.js Data ...
- DHTMLX 使用汇总
1.dhtmlxGrid 底部总出现滚动条 ------------------------------------------ 发现使用DHTMLXGRID时 GRID 底边总有 滚动条 测试 ...