文章目录打包和压缩概念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和unzipzip命令可以用来解压缩文件,或者对文件进行打包操作。zip是个使用广泛的压缩程序,文件经它压缩后会另外产生具有“.zip”扩展名的压缩文件。
安装