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 ...
随机推荐
- VB.Net条形码编程的方法
一.条形码的读取用过键盘口式的扫条码工具的朋友就知道,它就如同在鍵盘上按下数字鍵一样,基本不需任何编程和处理.但如果你使用的是其它接口的话,可能你就要为该设备编写通讯代码了.以下有一段简单的25针串口 ...
- CompletionPort
[CompletionPort] 1.CreateIoCompletionPort.此方法用于创建与绑定.此方法调用后,socket即退出,只能通过CompletionKey来辨认是哪个socket的 ...
- Spring中的注解配置-注入bean
在使用Spring框架中@Autowired标签时默认情况下使用 @Autowired 注释进行自动注入时,Spring 容器中匹配的候选 Bean 数目必须有且仅有一个.当找不到一个匹配的 Bean ...
- acoj-1735 输油管道 【中位数】
题目链接:http://acdream.info/problem?pid=1735 输油管道 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 2 ...
- Redis多API开发实践
一.Redis API支持 Redis提供了各类开发语言的API,方便开发语言连接使用Redis. https://redis.io/clients 官方网站提供了不同开发语言的API程序. Pyth ...
- Maven的pom.xml介绍
6.1 简介 pom.xml文件是Maven进行工作的主要配置文件.在这个文件中我们可以配置Maven项目的groupId.artifactId和version等Maven项目必须的元素:可以配置Ma ...
- nignx reload的时候报错invalid PID number
第一种思路是从PID号着手,提示无效PID号时nginx.pid文件为空,将进程的PID号追加到空的nginx.pid上,问题解决: 还有问题,请参考:https://www.cnblogs.com/ ...
- Linux之chmod使用
Linux文件分三种身份和四中权限. u:文件的拥有者 g:文件所属的群组 o:其他用户 对于每个身份,又有四种权限,分别为: r:读取文件的权限(read) w:写入文件的权限(write) x:执 ...
- ADO.NET DataTable的复制(clone)
using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=test;Integrated Se ...
- POP邮件收取邮件 代码
// 111111.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <WinSock.h> #include ...