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 ...
随机推荐
- Oracle数据库备份与恢复的三种方法
转自blueskys567原文Oracle数据库备份与恢复的三种方法, 2006-10. 有删改 Oracle数据库有三种标准的备份方法,它们分别是导出/导入(EXP/IMP).热备份和冷备份. 导出 ...
- jeesite快速开发平台(七)----代码生成原理
转自:https://blog.csdn.net/u011781521/article/details/79322942
- ACCESS 组合字段 order by 出错
ACCESS 组合字段 order by 出错 SELECT boardID,boardType,parentID,child,depth,rootID,(parentStr + ',' + boar ...
- np归纳总结(全)第一天
1.概述 1.np.array() # 将列表转换为数组 import numpy as np array = [1, 2, 3, 4, 5] array = np.array(array) 2.. ...
- Mysql 查询列名
#列名 select COLUMN_NAME from information_schema.columns where TABLE_SCHEMA='yunpiaobox_db' and table_ ...
- leetcode 63 不同的路径2
描述: 从左上角走到右下角,中间可能有若干阻碍: 题目给出一个矩阵,0表示可以走,1表示有障碍. 解决: 思路同第一题,只是如果上面或左边有障碍,自身不一定能走,注意些边界条件即可,复杂度仍是m*n. ...
- Visual Studio 2013 boost
E:\Visual Studio 2013\install\VC\bin\amd64>E:\IFC\boost_1_56_0_vs2013'E:\IFC\boost_1_56_0_vs2013' ...
- Golang基本结构之练习(day2)
笔记: . 任何一个代码文件隶属于一个包 . import 关键字,引用其他包: import(“fmt”) import(“os”) 通常习惯写成: import ( “fmt” “os” ) . ...
- java中double和float精度丢失问题
为什么会出现这个问题呢,就这是java和其它计算机语言都会出现的问题,下面我们分析一下为什么会出现这个问题:float和double类型主要是为了科学计算和工程计算而设计的.他们执行二进制浮点运算,这 ...
- MyBatis 插入主键方式和返回主键
这使用的mysql数据库,下面这种方式(没有给mysql设置自动增长)是插入主键方式: <insert id="insertBook" parameterType=" ...