linux命令之文件备份与压缩命令
1.tar:打包备份
该命令是将多个命令打包到一起,并且可以实现解压打包。打包是将多个文件或者目录变成一个总的文件,压缩则是将一个大的文件通过压缩算法变成一个小文件。
参数 | 说明 |
z(常用) | 通过gzip压缩或解压缩,一般都是以tar.gz结尾 |
j(常用) | 通过bzip2压缩和解压缩 一般都是以tar.bz2结尾 |
c(常用) | 创建新的tar包 |
v(常用) | 显示详细的tar命令执行过程 |
f(常用) | 指定压缩文件的名字,组合中一般f放到最后,因为f后面要立即接文件名 |
x(常用) | 解开tar包 |
C(常用) | 指定解压的目录路径 |
示例:
1)备份站点目录
[root@boxiaoyuan ~]# mkdir -p /var/www/html/boxiaoyuan/test
[root@boxiaoyuan ~]# touch /var/www/html/{..}.html
[root@boxiaoyuan ~]# ls /var/www/html
.html .html .html .html .html boxiaoyuan
.html .html .html .html .html
[root@boxiaoyuan ~]# cd /var/www/
[root@boxiaoyuan www]# cd html/
[root@boxiaoyuan html]# ls
.html .html .html .html .html .html .html .html .html .html
[root@boxiaoyuan html]# cd ..
[root@boxiaoyuan www]# tar zcvf www.tar.gz ./html/ # linux中一般都是以tar.gz结尾
./html/
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
2)查看压缩的内容
[root@boxiaoyuan www]# tar ztvf www.tar.gz
drwxr-xr-x root/root -- : ./html/
-rw-r--r-- root/root -- : ./html/.html
-rw-r--r-- root/root -- : ./html/.html
-rw-r--r-- root/root -- : ./html/.html
-rw-r--r-- root/root -- : ./html/.html
-rw-r--r-- root/root -- : ./html/.html
-rw-r--r-- root/root -- : ./html/.html
-rw-r--r-- root/root -- : ./html/.html
-rw-r--r-- root/root -- : ./html/.html
-rw-r--r-- root/root -- : ./html/.html
-rw-r--r-- root/root -- : ./html/.html
3)解压缩文件
[root@boxiaoyuan www]# tar zxvf www.tar.gz
./html/
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
./html/.html
3.zip:打包和压缩文件
该命令可以对文件进行压缩,与gzip相比,zip命令压缩文件不仅不会删除源文件,还可以压缩目录。
参数 | 说明 |
-r(常用) | 将指定目录下的所有文件和子目录一并压缩,递归压缩 |
-x(常用) | 压缩文件时排除某个文件 |
示例:
1)压缩文件
[root@boxiaoyuan html]# cd /tmp
[root@boxiaoyuan tmp]# cp /etc/services .
[root@boxiaoyuan tmp]# ls -alh services*
-rw-r--r--. root root 626K 4月 : services
[root@boxiaoyuan tmp]# zip service.zip ./services
adding: services (deflated %)
[root@boxiaoyuan tmp]# ls -alh service*
-rw-r--r--. root root 626K 4月 : services
-rw-r--r--. root root 125K 4月 : service.zip
2)压缩目录
[root@boxiaoyuan /]# zip -r tmp.zip ./tmp/
adding: tmp/ (stored %)
4.unzip:解压zip文件
该命令可以解压缩zip命令或者其他压缩软件压缩的zip格式的文件。
参数选项 | 解释说明 |
-l | 不解压显示压缩包文件列表 |
-o | 解压时不提示是否覆盖文件 |
-d | 指定解压目录 |
-v | 解压时显示信息信息 |
示例:
1)常规解压文件
[root@boxiaoyuan /]# unzip tmp.zip
Archive: tmp.zip
replace tmp/.X0-lock? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: tmp/.X0-lock
replace tmp/orbit-root/bonobo-activation-server-479f6d31a65026d71b1617890000c716-ior? [y]es, [n]o, [A]ll, [N]one, [r]ename: n
解压时如果不想要提示是否覆盖,可以使用unzip -o tmp.zip命令。
2)不解压显示文件内容-l选项
[root@boxiaoyuan /]# unzip -l tmp.zip
Archive: tmp.zip
Length Date Time Name
--------- ---------- ----- ----
-- : tmp/
-- : tmp/jetty-0.0.0.0--war-_-any-.dir/
-- : tmp/orbit-gdm/
-- : tmp/keyring-E58AUd/
-- : tmp/.X0-lock
-- : tmp/orbit-root/
tmp/winstone5092352002510277416.jar
--------- -------
files
注:本文内容为《跟老男孩学linux运维 核心系统命令实践》的学习笔记。
linux命令之文件备份与压缩命令的更多相关文章
- Linux常用命令大全 --- 文件备份和压缩命令
在linux中,常用的文件压缩工具有gzip.bzip2.zip . bzip2是最理想的压缩工具,它提供了最大限度的压缩.zip 兼容性好windows也支持 1.bzip2 命令 在shell 提 ...
- Linux基本命令(3)文件备份和压缩命令
文件备份和压缩命令 在Linux中,常用的文件压缩工具有gzip.bzip2.zip.bzip2是最理想的压缩工具,它提供了最大限度的压缩.zip兼容性好,Windows也支持. 命令 功能 bzip ...
- PHP调用Linux的命令行执行文件压缩命令&&创建文件夹修改权限
一开始,我和普通青年一样,想到用PHP内置的 ZipArchive纠结的是环境上没安装zip扩展,想采用用PHP调用Linux的命令行 ,执行压缩命令,感兴趣的朋友可以了解下,希望本文对你有所帮助 前 ...
- linux命令分享一:压缩命令
Linux操作系统中,*.zip.*.tar.*.tar.gz.*.tar.bz2.*.tar.xz.*.jar.*.7z等格式的压缩与解压 zip格式 压缩: zip -r [目标文件名].zip ...
- 第3章 常用linux命令 3.5 文件压缩命令
实验六 文件及目录的压缩解压缩相关命令的使用 [实验目的] 1.掌握linux压缩文件实质 2.掌握linux中压缩及解压缩指令的用法 [实验环境] 1. 标准配置PC一台 2. linux操作系统: ...
- linux tar.gz zip 解压缩 压缩命令
http://apps.hi.baidu.com/share/detail/37384818 download ADT link http://dl.google.com/android/ADT-0. ...
- linux tar.gz zip 减压 压缩命令
http://apps.hi.baidu.com/share/detail/37384818 download ADT link http://dl.google.com/android/ADT-0. ...
- 【转】linux tar.gz zip 解压缩 压缩命令
http://apps.hi.baidu.com/share/detail/37384818 download ADT link http://dl.google.com/android/ADT-0. ...
- Linux 常用解压和压缩命令
.tar 解包 tar xvf filename.tar.tar 打包 tar cvf filename.tar dirname.gz 解压1 gunzip filename.gz.gz 解压2 gz ...
随机推荐
- apache 搭建PHP多站点
修改apache 配置文件:httpd.conf 1.默认 Listen 80端口 2.添加配置如下: <VirtualHost *:80> ServerAdmin admin@yii.c ...
- oracle中bulk collect into用法
通过bulk collect减少loop处理的开销 采用bulk collect可以将查询结果一次性地加载到collections中. 而不是通过cursor一条一条地处理. 可以在select in ...
- 迷你MVVM框架 avalonjs 学习教程8、属性操作
属性操作是DOM操作很大的一块,它包括类名操作,表单元素的value属性操作,元素固有属性的管理,元素自定义属性的管理,某些元素的一些布尔属性的操作.大多数情况下,元素属性的值是字符串类型,我们称之为 ...
- modern.IE
1.主要测试IE浏览器的兼容性问题 2.网站上提供各种虚拟机来表现兼容性问题,可以像平常一样使用浏览器测试,但是中国访问速度比较慢 3.网址:http://loc.modern.ie/zh-cn/vi ...
- java线程池相关接口Executor和ExecutorService
在线程池的api中,Executor接口是最上层的接口,内部只有一个方法.如下: public interface Executor { void execute(Runnable command); ...
- 【poj2411】Mondriaan's Dream 状态压缩dp
AC传送门:http://vjudge.net/problem/POJ-2411 [题目大意] 有一个W行H列的广场,需要用1*2小砖铺盖,小砖之间互相不能重叠,问有多少种不同的铺法? [题解] 对于 ...
- react-navigation 3.x版本的安装以及react-native-gesture-handler配置
一.安装依赖,使用npm或yarn命令,3.x版本必须安装react-native-gesture-handler react-navigation react-native-gesture-hand ...
- Swift与OC的相互调用
Swift经过四年的发展已经趋于成熟,是时候学一下了,感谢公司swift大佬的不吝赐教.心有所感记录一下,如有不足欢迎指正批评. 新建swift项目 新建Swift.OC类文件 可在新建OC文件时,建 ...
- mybatis小工具
1.其实也不算是针对mybatis的其他都可以用 lombok 2.mybatis的小插件,可以快速定位到mapper.xml和接口之间 mybatisx
- SLAM拾萃(1):octomap
前言 大家好,时隔多年之后,我又开始了博客旅程.经历了很多事情之后呢,我发现自己的想法真的很简单:好好读书做课题,闲下来时写写博客,服务大家.所以我会继续写SLAM相关的博客.如果你觉得它对你有帮助, ...