1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 解压缩命令tar zip rar

解压缩命令tar zip rar

时间:2020-11-18 15:47:34

相关推荐

解压缩命令tar zip rar

文章目录

打包和压缩的概念tar常用独立命令打包压缩查阅tar包内有哪些文件解压缩到指定目录(默认是当前目录)只将tar内的部分文件解压出来其他命令(其他)zip和unziprar和unrar

打包和压缩的概念

tar命令可以为linux的文件和目录创建档案

利用tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件

tar最初被用来在磁带上创建档案,现在,用户可以在任何设备上创建档案。

利用tar命令,可以把一大堆的文件和目录全部打包成一个文件,这对于备份文件或将几个文件组合成为一个文件以便于网络传输是非常有用的。

首先要弄清两个概念:打包和压缩。 打包是指将一大堆文件或目录变成一个总的文件; 压缩则是将一个大的文件通过一些压缩算法变成一个小文件。

为什么要区分这两个概念呢?

这源于Linux中很多压缩程序只能针对一个文件进行压缩,这样当你想要压缩一大堆文件时,你得先将这一大堆文件先打成一个包(tar命令),然后再用压缩程序进行压缩(gzip

bzip2命令)。

tar

SYNOPSIStar [-] A --catenate --concatenate | c --create | d --diff --compare | --delete | r --append | t --list | --test-label | u --update | x --extract --get [options] [pathname ...]DESCRIPTIONTar stores and extracts files from a tape or disk archive.Tar从磁带或磁盘存档文件中存储和提取文件。

常用独立命令

FUNCTION LETTERSMain operation mode:-A, --catenate, --concatenateappend tar files to an archive将文件附加到存档文件中-c, --createcreate a new archive创建一个新的存档-d, --diff, --comparefind differences between archive and file system查找归档和文件系统之间的差异--deletedelete from the archive (not on mag tapes!)从存档中删除(不要在mag磁带上删除!)-r, --appendappend files to the end of an archive将文件附加到归档文件的末尾-t, --listlist the contents of an archive列出归档文件的内容--test-labeltest the archive volume label and exit-u, --updateonly append files newer than copy in archive只添加比存档中的副本更新的文件(—更新-x, --extract, --getextract files from an archive从归档文件中提取文件

重要:上面的命令是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个。

下面的参数是根据需要在压缩或解压档案时可选的。(其中-f命令是必选的)

打包压缩

tar -cvf log.tar log.log 仅打包,不压缩! tar -zcvf log.tar.gz log.log 打包后,以 gzip 压缩 tar -jcvf log.tar.bz2 log.log 打包后,以 bzip2 压缩 在选项f之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。 如果加z选项,则以.tar.gz或.tgz来代表gzip压缩过的tar包;如果加j选项,则以.tar.bz2来作为tar包名。-j, --bzip2-z, --gzip, --gunzip --ungzip-v, --verboseverbosely list files processed详细列出处理过的文件-f, --file ARCHIVEuse 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 DIRchange to directory DIR

只将tar内的部分文件解压出来

其他命令(其他)

-[0-7][lmh]specify drive and density指定驱动器和密度-a, --auto-compressuse archive suffix to determine the compression program使用archive后缀确定压缩程序--backupbackup before removal, choose version CONTROL--exclude=PATTERNexclude files, given as a PATTERN--exclude-ignore=FILEread exclude patterns for each directory from FILE, if it exists从文件中排除每个目录的模式(如果存在的话)--exclude-ignore-recursive=FILEread exclude patterns for each directory and its subdirectories from FILE, if it existsread从文件中排除每个目录及其子目录的模式(如果存在的话)--exclude-tag=FILEexclude contents of directories containing FILE, except for FILE itself排除包含文件的目录的内容,文件本身除外--exclude-tag-all=FILEexclude directories containing FILE排除包含文件的目录--exclude-tag-under=FILEexclude everything under directories containing FILE排除包含文件的目录下的所有内容-k, --keep-old-filesdon't replace existing files when extracting, treat them as errors解压时不要替换现有文件,将它们视为错误-m, --touchdon't extract file modified time不要提取文件修改时间-N, --newer, --after-date DATE-OR-FILEonly store files newer than DATE-OR-FILE只存储比DATE-OR-FILE更新的文件-O, --to-stdoutextract files to standard output将文件解压缩到标准输出-p, --preserve-permissions, --same-permissions 保留权限,相同权限extract information about file permissions (default for superuser)提取有关文件权限的信息(超级用户默认)--recursionrecurse into directories (default)递归到目录(默认)-U, --unlink-firstremove each file prior to extracting over it在提取每个文件之前删除它--unquoteunquote input file or member names (default)不用引号 对输入文件或成员名称(默认)--utcprint file modification times in UTC用UTC打印文件修改时间-w, --interactive, --confirmationask for confirmation for every action对每一个动作都要确认-W, --verifyattempt to verify the archive after writing it尝试在编写存档之后验证它-Z, --compress, --uncompress——压缩、解压缩EXAMPLESCreate archive.tar from files foo and bar.tar -cf archive.tar foo barList all files in archive.tar verbosely.tar -tvf archive.tarExtract 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或者可从/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 archivee 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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。