解压缩命令tar zip rar
文章目录
- 打包和压缩的概念
- tar
- 常用独立命令
- 打包压缩
- 查阅tar包内有哪些文件
- 解压缩到指定目录(默认是当前目录)
- 只将tar内的部分文件解压出来
- 其他命令(其他)
- zip和unzip
- rar和unrar
打包和压缩的概念
tar命令可以为linux的文件和目录创建档案
利用tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件
tar最初被用来在磁带上创建档案,现在,用户可以在任何设备上创建档案。
利用tar命令,可以把一大堆的文件和目录全部打包成一个文件,这对于备份文件或将几个文件组合成为一个文件以便于网络传输是非常有用的。首先要弄清两个概念:打包和压缩。 打包是指将一大堆文件或目录变成一个总的文件; 压缩则是将一个大的文件通过一些压缩算法变成一个小文件。
为什么要区分这两个概念呢?
这源于Linux中很多压缩程序只能针对一个文件进行压缩,这样当你想要压缩一大堆文件时,你得先将这一大堆文件先打成一个包(tar命令),然后再用压缩程序进行压缩(gzip
bzip2命令)。
tar
SYNOPSIS
tar [-] A --catenate --concatenate | c --create | d --diff --compare | --delete | r --append | t --list | --test-label | u --update | x --extract --get [options] [pathname ...]
DESCRIPTION
Tar stores and extracts files from a tape or disk archive.
Tar从磁带或磁盘存档文件中存储和提取文件。
常用独立命令
FUNCTION LETTERS
Main operation mode:
-A, --catenate, --concatenate
append tar files to an archive
将文件附加到存档文件中
-c, --create
create a new archive
创建一个新的存档
-d, --diff, --compare
find differences between archive and file system
查找归档和文件系统之间的差异
--delete
delete from the archive (not on mag tapes!)
从存档中删除(不要在mag磁带上删除!)
-r, --append
append files to the end of an archive
将文件附加到归档文件的末尾
-t, --list
list the contents of an archive
列出归档文件的内容
--test-label
test the archive volume label and exit
-u, --update
only append files newer than copy in archive
只添加比存档中的副本更新的文件(—更新
-x, --extract, --get
extract files from an archive
从归档文件中提取文件
重要:上面的命令是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个。
下面的参数是根据需要在压缩或解压档案时可选的。(其中-f命令是必选的)
打包压缩
tar -cvf log.tar log2012.log 仅打包,不压缩!
tar -zcvf log.tar.gz log2012.log 打包后,以 gzip 压缩
tar -jcvf log.tar.bz2 log2012.log 打包后,以 bzip2 压缩
在选项f之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。
如果加z选项,则以.tar.gz或.tgz来代表gzip压缩过的tar包;
如果加j选项,则以.tar.bz2来作为tar包名。
-j, --bzip2
-z, --gzip, --gunzip --ungzip
-v, --verbose
verbosely list files processed
详细列出处理过的文件
-f, --file ARCHIVE
use archive file or device ARCHIVE
使用存档文件或设备存档(指定存档文件)
切记,这个参数是最后一个参数,后面只能接档案名。
tar 命令 必须和-f命令连用
在选项f之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。 如果加z选项,则以.tar.gz或.tgz来代表gzip压缩过的tar包;如果加j选项,则以.tar.bz2来作为tar包名。
查阅tar包内有哪些文件
tar -ztvf log.tar.gz
由于我们使用 gzip 压缩的log.tar.gz,所以要查阅log.tar.gz包内的文件时,就得要加上z这个选项了。t的意思是查看文档内容
解压缩到指定目录(默认是当前目录)
tar -xvf archive.tar -C /tmp 将压缩包释放到 /tmp目录下
jz选项依据压缩属性需要加上
-C, --directory DIR
change to directory DIR
只将tar内的部分文件解压出来
其他命令(其他)
-[0-7][lmh]
specify drive and density
指定驱动器和密度
-a, --auto-compress
use archive suffix to determine the compression program
使用archive后缀确定压缩程序
--backup
backup before removal, choose version CONTROL
--exclude=PATTERN
exclude files, given as a PATTERN
--exclude-ignore=FILE
read exclude patterns for each directory from FILE, if it exists
从文件中排除每个目录的模式(如果存在的话)
--exclude-ignore-recursive=FILE
read exclude patterns for each directory and its subdirectories from FILE, if it exists
read从文件中排除每个目录及其子目录的模式(如果存在的话)
--exclude-tag=FILE
exclude contents of directories containing FILE, except for FILE itself
排除包含文件的目录的内容,文件本身除外
--exclude-tag-all=FILE
exclude directories containing FILE
排除包含文件的目录
--exclude-tag-under=FILE
exclude everything under directories containing FILE
排除包含文件的目录下的所有内容
-k, --keep-old-files
don't replace existing files when extracting, treat them as errors
解压时不要替换现有文件,将它们视为错误
-m, --touch
don't extract file modified time
不要提取文件修改时间
-N, --newer, --after-date DATE-OR-FILE
only store files newer than DATE-OR-FILE
只存储比DATE-OR-FILE更新的文件
-O, --to-stdout
extract files to standard output
将文件解压缩到标准输出
-p, --preserve-permissions, --same-permissions 保留权限,相同权限
extract information about file permissions (default for superuser)
提取有关文件权限的信息(超级用户默认)
--recursion
recurse into directories (default)
递归到目录(默认)
-U, --unlink-first
remove each file prior to extracting over it
在提取每个文件之前删除它
--unquote
unquote input file or member names (default)
不用引号 对输入文件或成员名称(默认)
--utc
print file modification times in UTC
用UTC打印文件修改时间
-w, --interactive, --confirmation
ask for confirmation for every action
对每一个动作都要确认
-W, --verify
attempt to verify the archive after writing it
尝试在编写存档之后验证它
-Z, --compress, --uncompress
——压缩、解压缩
EXAMPLES
Create archive.tar from files foo and bar.
tar -cf archive.tar foo bar
List all files in archive.tar verbosely.
tar -tvf archive.tar
Extract all files from archive.tar.
tar -xf archive.tar
zip和unzip
zip命令可以用来解压缩文件,或者对文件进行打包操作。zip是个使用广泛的压缩程序,文件经它压缩后会另外产生具有“.zip”扩展名的压缩文件。
安装
zip all.zip *.jpg 这条命令是将所有.jpg的文件压缩成一个zip包
unzip all.zip 这条命令是将all.zip中的所有文件解压出来
zip -r file1.zip file1 file2 dir1 将几个文件和目录同时压缩成一个zip格式的压缩包
-r:递归处理,将指定目录下的所有文件和子目录一并处理;
-v:显示指令执行过程或显示版本信息;
rar和unrar
安装: sudo apt-get install rar unrar
或者可从http://www.rarsoft.com/download.htm下载 RAR for Linux 编译安装
# tar -xzpvf rarlinux-3.8.0.tar.gz
# cd rar
# make
这样就安装好了,安装之后就有了rar和unrar这两个程序,rar是压缩程序,unrar是解压程序。它们的参数选项很多,可用命令rar -help和unrar -help查看,这里亦简单举例说明一下其用法:
a Add files to archive
e Extract files without archived paths
# rar a test.rar test.jpg test.png
这条命令是将test.jpg和test.png压缩成一个rar包
# rar a test.rar *.jpg
这条命令是将所有.jpg的文件压缩成一个rar包
# rar a test.rar test
这条命令是将文件夹test压缩成一个rar包
# unrar e test.rar
这条命令是将test.rar中的所有文件解压出来
也可以用 rar e test.rar
还没有评论,来说两句吧...