首页 > 编程知识 正文

tar和zip的区别,解压zip包命令

时间:2023-05-06 06:30:16 阅读:23233 作者:3660

文章目录打包和压缩概念tar常规独立命令打包压缩tar包中的哪些文件已解压缩到指定的目录中。 缺省值为当前目录。 仅解压缩tar中的部分文件,并解压缩其他命令(其他) zip、unziprar和unrar

打包和压缩概念

tar命令创建linux文件和目录文件

使用tar,可以为特定文件创建文件(备份文件)、修改文件中的文件以及将新文件添加到文件中

tar最初用于在磁带上创建归档文件,用户现在可以在任何设备上创建归档文件。

使用tar命令,可以将所有大量的文件和目录打包到一个文件中。 这有助于备份文件或将多个文件合并为一个文件,以方便网络传输。

首先,必须阐明两个概念:打包和压缩。 打包是指将大量文件或目录组合为一个文件。 压缩是指通过一些压缩算法将大文件变成小文件。

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

这是因为Linux上的许多压缩程序只能压缩一个文件,因此如果bmddw要压缩大量文件,它首先将大量文件合并到一个包中(tar命令),然后用压缩程序压缩(gzip )

bzip2命令)。

tarsynopsistar [-- ] DCD XYZ|x-- extract-- get [ options ] [ pathname . ] descriptiontarstoresandextractsfilesfromatapeoope常用独立命令functionlettersmainoperationmode :-- a,--catenate, --concatenateappendtarfilestoanarchive将文件附加到归档文件--c, --create create a new archive通过创建新的归档----diff---comparefinddifferencesbetweenarchiveandfilesystem来创建归档和文件系统-r,--appendappendfilestotheendofanarchive将文件附加到归档文件的末尾。 -t,- listlistthecontentsofanarchive归档文件的内容--test-labeltestthearchivevolumelabelandexit-u, -仅添加更新自updateonlyappendfilesnewerthancopyinarchive归档文件中副本的文件- -更新--x,- -提取,- -获取提取文件来自

如果需要,可以在压缩或解压缩文件时选择以下参数: (其中-f命令是必需的)

包装压缩tar -cvf log.tar log2012.log仅包装不压缩! tar -zcvf log.tar.gz log2012.log包后,gzip压缩tar -jcvf log.tar.bz2 log2012.log包后,bzip2压缩中选项f后的文档文件名自行附加如果要添加j选项,请将. tar.bz2作为tar包名称。 -j,--bzip2 -z,--gzip,----gunzip----ungzip-v,----f已处理的verboseverboselylistfilesprocesssed文件--------------------- - 添加z选项时,gzip压缩的tar包以. tar.gz或. tgz表示。 如果要添加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从文件中排除每个目录及mldxte目录的模式(如果存在的话) --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


版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。