linux在文件打包和压缩
1. 打包和压缩文件
2. gzip压缩
$ gzip -h
gzip 1.3.3
(2002-03-08)
usage: gzip [-cdfhlLnNrtvV19] [-S suffix] [file ...]
经常使用參数
-c : 压缩数据输出到屏幕,可重定向处理
-d : 解压缩
-t : 检验压缩文件的一致性。看看文件是否错误
-v : 显示压缩的具体信息。压缩比等
-# : 数字,压缩等级,1-9,9压缩率最高,默认6
压缩文件
$ gzip -v test
test: 53.1% -- replaced with test.gz
压缩会删掉本地文件。新建test.gz文件
$ gzip -c test > test.gz
查看压缩后的文件内容,不解压缩的情况下。使用zcat命令
$ zcat test.gz
3. bzip2
$ bzip2 -h
bzip2, a block-sorting file compressor. Version 1.0.2, 30-Dec-2001. usage: bzip2 [flags and input files in any order]
经常使用參数
-c : 压缩数据输出到屏幕。可重定向处理
-d : 解压缩
-k : 保留原文件
-z : 压缩
-t : 检验压缩文件的一致性。看看文件是否错误
-v : 显示压缩的具体信息。压缩比等
-# : 数字,压缩等级。1-9,9压缩率最高。默认6
使用
#压缩test文件,生成test.bz2
$ bzip2 -z test #保留原文件, 压缩生成test.bz2
$ bzip2 -k test #解压缩文件
$ bzip2 -d test.bz2
查看压缩文件内容,使用bzcat
$ bzcat test.bz2
3. 打包:tar
$ tar --help
GNU `tar' saves many files together into a single tape or disk archive, and
can restore individual files from the archive. Usage: tar [OPTION]... [FILE]... Examples:
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xf archive.tar # Extract all files from archive.tar. #參数
-c 新建压缩文件
-t 列出压缩文件列表
-x 解压缩文件
-c,-t,-x不能同一时候出现 -j 通过bzip2来压缩或解压缩。文件名称最好为. *.tar.bz2
-z 通过gzip压缩或解压缩, 文件名称最好为 *.tar.gz
-v 展示正在处理的具体信息
-f 后面跟要被处理的文件名称
-C 解压时,后面跟解压到的文件夹名 -p 保留文件的原本权限
-P 保留绝对路径
--exclude=FILE 排除FILE文件
tar的基本使用方法
#创建bzip2压缩文件
$ tar -jcv -f test.tar.bz2 test/
test/
test/1
test/10 #创建gzip压缩文件
$ tar -zcv -f test.tar.gz test
test/
test/1
test/10 #查看文件
$ ll
drwxrwxr-x 2 work work 4096 Jul 19 19:12 test
-rw-rw-r-- 1 work work 61897 Jul 19 19:13 test.tar.bz2 #不解压缩情况下查看文件列表
$ tar -jtv -f test.tar.bz2
tar: Record size = 8 blocks
drwxrwxr-x work/work 0 2014-07-19 19:12:40 test/
-rw-rw-r-- work/work 6353 2014-07-19 19:12:40 test/1
-rw-rw-r-- work/work 6343 2014-07-19 19:12:40 test/10 #解压缩到当前文件夹
$ tar -jxv -f test.tar.bz2
test/
test/1
test/10 #解压缩到指定文件夹test2
$ mkdir test2
$ tar -jxv -f test.tar.bz2 -C test2
test/
test/1
test/10 #保留原文件权限
$ tar -zcvp -f etc.tar.gz /etc #查看压缩文件
$ tar -ztv -f etc.tar.gz
打包时不包括某个文件
#创建压缩文件,不包括某个文件test/10
$ tar -zcv -f test.tar.gz --exclude=test/10 test/*
test/1
备份比某个时刻更新的文件
$ tar -zcv -f etc.tar.gz --newer-mtime="2013/10/31" /etc/*
/etc/xinetd.d/
tar: /etc/yp.conf: file is unchanged; not dumped
#not dumpd表示没有备份的
版权声明:本文博主原创文章,博客,未经同意不得转载。
linux在文件打包和压缩的更多相关文章
- linux的文件打包与压缩
简介 Linux 上常用的压缩/解压工具,介绍了zip.rar.tar的使用. 文件打包和压缩 Linux 上的压缩包文件格式,除了 Windows 最常见的*.zip.*.rar..7z 后缀的压缩 ...
- linux:文件打包与压缩
学习内容介绍:Linux 上常用的压缩/解压工具,介绍了zip.rar.tar的使用. 先总结一下常用命令: zip: 打包 :zip something.zip something (目录请加 -r ...
- linux下文件打包、压缩详解
Linux平台下,有如下几种常见的压缩工具: ========================================================================= 工 具 ...
- Linux 将文件打包、压缩并分割成指定大小
打包文件: tar -cvf .tar 分割文件: split -b 3G -d -a .tar .tar. //使用split命令,-b 3G 表示设置每个分割包的大小,单位还是可以k // -d ...
- linux学习-文件打包与压缩
- linux常用命令之--文件打包与压缩命令
linux的文件打包与压缩命令 1.压缩与解压命令 compress:用于压缩指定的文件,后缀为.z 其命令格式如下: compress [-d] 文件名 常用参数: -d:解压被压缩的文件(.z为后 ...
- Linux 系统常用命令汇总(六) 文件打包与压缩
文件打包与压缩 命令 选项 注解 示例 compress 文件名 压缩指定的文件,压缩后的格式为*.z compress install.log -d 解压被压缩的文件 .z为后缀的文件:compr ...
- linux下的打包和压缩
linux中常见的两种压缩包文件的格式是.tar..gz和.tar.gz..tar仅仅是将文件简单地打包,文件的大小没有变化,也就是说.tar文件仅仅是一个包,没有被压缩:.tar.gz文件是打包后用 ...
- Linux基础------文件打包解包---tar命令,文件压缩解压---命令gzip,vim编辑器创建和编辑正文件,磁盘分区/格式化,软/硬链接
作业一:1) 将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) cat /etc/passwd /etc/group > /1.txt2) 将用户信息数据库文件和用户 ...
随机推荐
- NSLog用法,打印日志
要输出的格式化占位: %@ 对象 %d, %i 整数 %u 无符整形 %f 浮点/双字 %x, %X 二进制整数 %o 八进制整数 %zu size_t %p 指针 %e 浮点/双字 (科 ...
- C# 超级简单的Telnet (TcpClient)客户端
基于Sockets 没什么好说的,代码说明了所有 using System; using System.Collections.Generic; using System.Linq; using Sy ...
- 通过JS控制textarea的输入长度
废话不多说,直接上代码(因为自己也只是遇到的时候然后上网查到的解决办法,放在此处只是为了方便各位看以及以后再碰到用起来方便) <ul> <li> <textarea ro ...
- Mysql 细节记忆
DELIMITER $$ 和 DELIMITER ; DROP PROCEDURE IF EXISTS `pro_follow_getBookBeforeExpired`$$ DECLARE p_Se ...
- OD学习笔记10:一个VB程序的加密和解密思路
前边,我们的例子中既有VC++开发的程序,也有Delphi开发的程序,今天我们给大家分析一个VB程序的加密和解密思路. Virtual BASIC是由早期DOS时代的BASIC语言发展而来的可视化编程 ...
- Combination Sum,Combination Sum II,Combination Sum III
39. Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique co ...
- arm汇编(c内嵌汇编及c和汇编互调)
C语言编译成汇编: arm-linux-gcc -S test.c -o test.S C语言编译成可执行文件: arm-linux-gcc test.c -o test 多个文件编译链接: arm- ...
- Qt中gb2312/GBK的URL编解码函数
编码函数: QByteArray encodeURI(QString str) { QByteArray array; QTextCodec *codec=QTextCodec::codecForNa ...
- 三个重要的游标sp_cursoropen
請問這三個存諸過程的作用是什么﹖ sp_cursoropen, sp_cursorfetch, sp_cursorclose API 服务器游标实现 SQL Server OLE DB 提供程序. ...
- Jasper_passValue_return value from the subreport to main report
create a variable In subreport say returnValue variable class type --> whatever u want calculati ...