当前位置: 首页 > news >正文

外贸营销单页网站网站建设与应用教案

外贸营销单页网站,网站建设与应用教案,石家庄建设,自己可以做类似淘宝客网站吗1.命令作用 命令tar将许多文件一起保存到单个磁带或磁盘存档中#xff0c;并且可以从存档中恢复单个文件(GNU tar saves many files together into a single tape or disk archive, and can restore individual files from the archive.)。 2.命令语法 Usage: tar [OPTION.…1.命令作用 命令tar将许多文件一起保存到单个磁带或磁盘存档中并且可以从存档中恢复单个文件(GNU tar saves many files together into a single tape or disk archive, and can restore individual files from the archive.)。 2.命令语法 Usage: tar [OPTION...] [FILE]... 2.简单举例 tar -cf archive.tar foo bar将文件foo和bar创建一个tar格式的归档(archive.tar)。  tar -tvf archive.tar详细列出archive.tar中的所有文件。  tar -xf archive.tar从archive.tar中提取所有文件。 3.参数详解 OPTION: ①主要运行方式 -A, --catenate, --concatenate将tar文件附加到另一个tar文件(归档文件)中需与-f 参数一起使用仅可一个一个tar文件附加不可多个tar文件一次性附加-c, --create创建一个新的归档文件需与-f 参数一起使用-d, --diff, --compare查找归档中文件和系统上解压后的文件之间的差异系统上解压后的文件多了不会输出如果解压后的文件少了则会输出提示需与-f、-v 参数一起使用--delete从存档中删除文件或者目录删除的文件和目录可以使用tar -tf 查看-r, --append将文件追加到存档文件末尾需与-f 参数一起使用-t, --list列出存档的内容列表需与-f 参数一起使用--test-label测试归档卷标签并退出用于自动化脚本验证归档的存在和卷标是否符合要求-u, --update只追加比归档文件中比列表文件更新的文件需与-f、-v 参数一起使用使用-tf 查看更新后的归档文件列表是追加方式即列表中存在多个不同版本但相同名称的文件注意解压后仅只保留版本最新的文件-x, --extract, --get从存档中提取全部文件或者指定文件名称进行提取通常与-f、-v 参数一起使用 ②操作修饰符 --check-device在创建或增量存档时检查设备(默认)-g, --listed-incrementalFILE处理新GNU格式的增量归档需要保留所有的归档增量归档解压需要指定快照文件全量归档加多个增量归档可以进行备份-G, --incremental处理旧GNU格式增量备份与-g用法类似--ignore-failed-read解压归档时当归档中有不可读的文件(归档存在损坏情况)不会因为非零退出而是继续提取归档中获取文件对损坏的归档解压场景很有用默认情况下遇到错误直接退出简而言之即忽略错误继续解压默认遇到错误直接退出--levelNUMBER指定全量归档的增量归档文件的转储级别全量为--level0增量依次为1、2、3、...通常与-g参数一起使用-n, --seek归档可查找tar -cn ...tar显示tar文件中所有文件内容--no-check-device在创建或增量归档时不检查设备--no-seek归档不可查--occurrence[NUMBER]只处理存档中每个文件的第number次出现此选项仅在与子命令---delete、--diff、--extract或--list一起使用时有效并且当在命令行上或通过-T选项给出文件列表时有效NUMBER默认为1--sparse-versionMAJOR[.MINOR]设置要使用的稀疏格式的版本暗含--sparse-S, --sparse有效地处理稀疏文件 ③输入控制覆盖寄存器 -k, --keep-old-files提取时不提取系统中已存在的现有文件将其视为错误--keep-directory-symlink提取时保留到目录的现有符号链接tar默认会保留符号链接与--dereference参数相反--keep-newer-files提取时不提取系统中现有文件比归档中文件版本新或者与归档中文件版本一致的文件即如果归档中有新版本的文件会被提取覆盖系统中的现有文件--no-overwrite-dir提取归档时保留已存在目录的元数据(比如用户和读写权限)只有系统上存在多层目录时才有效且对最内层目录无效可使用stat dir查看其中Access、Modify、Change时间会有所变化--overwrite提取归档时覆盖已存在的文件--overwrite-dir提取归档时覆盖已存在目录的元数据(默认)与--no-overwrite-dir效果相反--recursive-unlink在提取目录之前去除目录递归(删除目录文件夹)无明显效果与默认差不多--remove-files将文件添加到存档后删除文件同样适用于目录归档--skip-old-files提取时不要替换现有文件静默地跳过它们与-k类似-U, --unlink-first在对每个文件进行提取之前先删除它-W, --verify在写入归档文件后尝试验证它 ④选择输出流 --ignore-command-error忽略命令错误而导致执行退出主要处理外部压缩工具gzip、bzip2时的错误怎么处理启动参数会跳过错误继续执行未启动参数报错后立即终止压缩/解压--no-ignore-command-error将非零退出视为错误与--ignore-command-error相反-O, --to-stdout将文件提取到标准输出--to-commandCOMMAND管道提取文件到另一个程序 ⑤文件属性的处理 --atime-preserve[METHOD]保留对转储文件的访问时间或者通过恢复读取后的时间(METHODreplace默认)或不首先设置时间(METHODsystem)测试无效果--delay-directory-restore将解压目录的修改次数和权限设置延迟到解压结束无效果--groupNAME创建归档时强制NAME作为添加文件的组权限名称--modeCHANGES强制(符号)模式对新增文件的更改无法使用没说明模式可设置哪些参数--mtimeDATE-OR-FILE创建归档时设置归档中文件的mtime为DATE-OR-FILE-m, --touch不提取文件修改时间--no-delay-directory-restore取消--delay-directory-restore选项的效果无效果--no-same-owner按照自己的方式提取文件即强制文件归属当前用户(默认为普通用户)--no-same-permissions在从归档文件中提取权限时应用用户的umask(默认为普通用户)--numeric-owner始终使用数字作为用户/组名--ownerNAME创建归档时强制NAME作为添加文件的所有者-p, --preserve-permissions, --same-permissions提取有关文件权限的信息(默认为超级用户)测试无效果--preserve和-p和-s一样提示已经不再使用--same-owner尝试提取与存档中存在的所有权相同的文件(默认为超级用户)-s, --preserve-order, --same-order成员参数的列出顺序与存档中的文件相同测试无效果 ⑥扩展文件属性的处理(通常不会使用到) --acls启用POSIX acl支持--no-acls关闭POSIX acl支持--no-selinux禁用SELinux上下文支持--no-xattrs禁用扩展属性支持--selinux启用SELinux上下文支持--xattrs启用扩展属性支持--xattrs-excludeMASK指定xattr键的排除模式--xattrs-includeMASK为xattr键指定包含模式 ⑦设备选择和切换 -f, --fileARCHIVE使用归档文件或归档设备--force-local归档文件是本地的即使它有冒号通常冒号是远程文件的书写格式使用该参数强制将带有冒号的文件名称视为本地文件-F, --info-scriptNAME, --new-volume-scriptNAME在每个磁带的末尾运行脚本暗含-M-L, --tape-lengthNUMBER写入NUMBER * 1024字节后更改磁带-M, --multi-volume创建/列表/提取多卷存档--rmt-commandCOMMAND使用给定的rmt命令而不是rmt--rsh-commandCOMMAND使用远程命令代替rsh--volno-fileFILE使用/update文件中的卷号 ⑧装置块Device blocking -b, --blocking-factorBLOCKSBLOCKS x每条记录512字节-B, --read-full-records读取时重新阻塞4.2BSD管道-i, --ignore-zeros忽略归档中的归零块意味着EOF--record-sizeNUMBER每条记录的字节数512的倍数 ⑨档案格式选择 -H, --formatFORMAT创建给定格式的存档FORMAT是下列选项之一 gnu        GNU tar 1.13.x format(默认格式支持长文件名、大文件及扩展元数据)oldgnu   GNU format as per tar 1.12pax        POSIX 1003.1-2001 (pax) formatposix      same as pax(跨平台兼容性好但功能限制多)ustar      POSIX 1003.1-1988 (ustar) formatv7          old V7 tar format --old-archive, --portability与--formatv7相同--pax-optionkeyword[[:]value][,keyword[[:]value]]...控制pax的关键字需要与--formatpax一起使用keywordvalue可设置为charsetUTF-8、mtime:%s.%N、deleteuid、deletegid--posix与--formatposix相同-V, --labelTEXT创建归档时定义一个标签为TEXT在查看归档内容(-t)和提取归档时显示标签TEXT内容 ⑩压缩选项 -a, --auto-compress使用归档后缀来确定压缩程序-I, --use-compress-programPROG通过PROG压缩方式归档(必须接受-d)简言之通过-l指定压缩方式PROG可取值bzip2、xz、lzip-j, --bzip2通过bzip2压缩归档文件归档命名后缀为.tar.bz2-J, --xz通过xz压缩归档文件归档命名后缀为.tar.xz--lzip通过lzip压缩归档文件归档命名后缀为.tar.lz测试报错--lzma通过lzma压缩归档文件归档命名后缀为.tar.lzma测试报错--lzop通过lzma压缩归档文件归档命名后缀为.tar.lzo--no-auto-compress不使用归档后缀来确定压缩程序与-a参数相反-z, --gzip, --gunzip, --ungzip通过gzip压缩归档文件归档命名后缀为.tar.gz-Z, --compress, --uncompress通过compress压缩归档文件归档命名后缀为.tar.Z ⑪本地文件选择 --add-fileFILE将给定的文件添加到存档(如果其名称以破折号开头则很有用)测试发现不是追加是替换效果--backup[CONTROL]删除前备份选择版本控制提取压缩归档时系统已存在文件进行版本控制和备份CONTROL可取值有none / off(不备份直接覆盖默认值)、numbered / t(创建带数字的后缀备份)、nil / existing(如之前有带数字的后缀就继续数字备份否者使用简单后缀)、never / simple(简单后缀)-C, --directoryDIR更改为目录DIR而不是默认的当前目录--excludePATTERN排除文件以PATTERN形式给出(创建/提取归档都适用)--exclude-backups排除备份和锁定文件--exclude-caches排除包含CACHEDIR的目录内容。TAG除了标记文件本身--exclude-caches-all排除包含CACHEDIR.TAR的目录--exclude-caches-under排除包含CACHEDIR.TAR目录下的所有内容--exclude-tagFILE排除包含FILE的目录的内容除了FILE本身--exclude-tag-allFILE排除包含FILE的目录--exclude-tag-underFILE排除包含FILE的目录下的所有内容--exclude-vcs排除版本控制系统目录归档时会自动跳过.git .svn .hg等版本控制目录及其目录下所有的文件和目录-h, --dereference创建归档时将软链接转储为它们指向的实际文件即软链接会变成实际的文件或者目录--hard-dereference创建归档时将硬链接转储为它们所引用的文件即硬链接会变成实际的文件或者目录-K, --starting-fileMEMBER-NAME提取归档时从MEMBER-NAME开始提取MEMBER-NAME名称可以通过tar -tf查看-tf查看时也可以使用该参数--newer-mtimeDATE仅比较数据更改时的日期和时间--no-null-T参数使用时指定文件命令列表的分隔方式该方式为换行\n为默认值--no-recursion指定归档的目录层级指定的目录层级之下的文件或者目录不会被归档--no-unquote不取消用-T读取的文件名的引号--null-T参数使用时指定文件命令列表的分隔方式与--no-null对立-N, --newerDATE-OR-FILE, --after-dateDATE-OR-FILE归档ctime在DATE-OR-FILE指定时间及其之后的文件--one-file-system在创建存档时保留在本地文件系统中的中归档备份/目录不归档/proc、/mnt、/dev等挂载内容-P, --absolute-names不要从文件名中去掉前导/(更目录)--recursion递归到目录(默认)--suffixSTRING删除前备份覆盖通常的后缀(~除非被环境变量SIMPLE_BACKUP_SUFFIX覆盖)指定后备份后缀还是~-T, --files-fromFILE从FILE文件内容指定的文件名称列表提取/创建归档--unquote用-T读取的文件名取消引号(默认)-X, --exclude-fromFILE排除FILE文件中列出的文件或者目录与-T相反 ⑫文件名转换 --strip-componentsNUMBER提取时从文件名中剥离前NUMBER层目录--transformEXPRESSION, --xformEXPRESSION使用sed替换表达式来转换文件名 ⑬文件名匹配选项影响排除和包含模式 --anchored模式匹配文件名开头--ignore-case忽略大小写匹配比如使用--exclude时使用--no-anchored模式匹配任何 / (默认为排除)--no-ignore-case区分大小写匹配(默认)--no-wildcards逐字字符串匹配--no-wildcards-match-slash通配符不匹配 /--wildcards使用通配符(默认)--wildcards-match-slash通配符匹配 / (默认排除) ⑭信息输出 --checkpoint[NUMBER]根据NUMBER值显示创建/提取归档进度(默认为10)--checkpoint-actionACTION在每个检查点上执行ACTION--full-time创建归档/查看归档时显示文件目录更详细的时间信息--index-fileFILE将标准输出输出到FILE-l, --check-links如果不是所有链接都被转储则打印一条消息--no-quote-charsSTRING禁用字符串字符的引号--quote-charsSTRING另外引用字符串中的字符--quoting-styleSTYLE设置名称引用样式下面是有效的STYLE值   literal  shell  shell-always  c  c-maybe  escape  locale  clocale -R, --block-number显示每条消息存档中的块号如tar -Rtf file.tar--show-defaults显示tar默认值如tar --show-defaults--show-omitted-dirs列出或提取出现错误时列出不匹配搜索条件的每个目录--show-transformed-names, --show-stored-names-tf查看列表显示转换后的文件或存档名称与--transform参数或者--strip-components参数一起使用--totals[SIGNAL]打印归档处理后的总字节数tar -cvf test.tar *.txt --totals--utc以UTC格式打印文件修改时间-cvf与-tf创建归档和查看归档列表时使用-v, --verbose标准输出处理过程中的相关信息--warningKEYWORD告警控制可取值none(禁止所有告警)、all(启动所有告警)、no-timestamp(忽略归档中的时间戳异常的告警)-w, --interactive, --confirmation每归档一个目标都要输入y确认 ⑮其他选择 -?, --help给出以下帮助列表--restrict禁用一些可能有害的选项--usage给出简短的用法信息--version打印程序版本 ⑯tar默值可通过tar --show-defaults查看 --formatgnu -f- -b20 --quoting-styleescape --rmt-command/etc/rmt --rsh-command/usr/bin/ssh 4.常用用例 4.1.归档文件内容查看 ## 查看归档文件(tar文件)内的文件列表 [rootnode1 test]# tar -tf file1.txt.tar file1.txt [rootnode1 test]# 4.2.主动运行方式 4.2.1.将一个归档文件附加到另一个归档文件中 [rootnode1 test]# tar -tf file1.txt.tar file1.txt [rootnode1 test]# tar -tf file2.txt.tar file2.txt [rootnode1 test]# tar -Af file1.txt.tar file2.txt.tar [rootnode1 test]# tar -tf file1.txt.tar file1.txt file2.txt [rootnode1 test]# 4.2.2.对比归档文件与解压后文件系统中文件的差异 [rootnode1 test]# ll total 643712 -rw-r--r--. 1 root root 439439360 May 13 22:50 file1.txt.tar -rw-r--r--. 1 root root 219719680 May 13 22:49 file2.txt.tar [rootnode1 test]# tar -xvf file1.txt.tar file1.txt file2.txt [rootnode1 test]# tar -dvf file1.txt.tar ## 文件一致仅输出归档文件内容列表 file1.txt file2.txt [rootnode1 test]# ll total 1072840 -rw-r--r--. 1 root root 219712350 May 13 22:21 file1.txt -rw-r--r--. 1 root root 439439360 May 13 22:50 file1.txt.tar -rw-r--r--. 1 root root 219712350 Mar 2 03:05 file2.txt -rw-r--r--. 1 root root 219719680 May 13 22:49 file2.txt.tar [rootnode1 test]# rm -rf file2.txt [rootnode1 test]# tar -dvf file1.txt.tar ## 文件不一致输出归档文件内容列表且输出不存在的文件提升 file1.txt file2.txt tar: file2.txt: Warning: Cannot stat: No such file or directory [rootnode1 test]# 4.2.3.删除归档文件中的指定内容 [rootnode1 test]# tar -tf file1.txt.tar file1.txt file2.txt [rootnode1 test]# tar --delete -f file1.txt.tar file1.txt [rootnode1 test]# tar -tf file1.txt.tar file2.txt [rootnode1 test]# 4.2.4.将文件追加到存档文件末尾 [rootnode1 test]# ll total 643708 -rw-r--r--. 1 root root 219712350 May 13 23:13 file1.txt -rw-r--r--. 1 root root 219719680 May 13 23:07 file1.txt.tar -rw-r--r--. 1 root root 219719680 May 13 22:49 file2.txt.tar [rootnode1 test]# tar -tf file1.txt.tar file2.txt [rootnode1 test]# tar -rf file1.txt.tar file1.txt [rootnode1 test]# tar -tf file1.txt.tar file2.txt file1.txt [rootnode1 test]# 4.2.5.验证归档文件是否存在 [rootnode1 test]# ll total 643704 -rw-r--r--. 1 root root 439429120 May 13 23:18 file1.txt.tar -rw-r--r--. 1 root root 219719680 May 13 22:49 file2.txt.tar [rootnode1 test]# tar --test-label -f file2.txt.tar [rootnode1 test]# echo $? 0 [rootnode1 test]# tar --test-label -f file3.txt.tar tar: file3.txt.tar: Cannot open: No such file or directory tar: Error is not recoverable: exiting now [rootnode1 test]# echo $? 2 [rootnode1 test]# 4.2.6.更新归档文件里面更新过的新版本文件 [rootnode1 Desktop]# tar -tf file.tar file1.txt file2.txt file3.txt file4.txt [rootnode1 Desktop]# vi file2.txt [rootnode1 Desktop]# [rootnode1 Desktop]# tar -uvf file.tar file1.txt file2.txt file3.txt file4.txt file2.txt [rootnode1 Desktop]# tar -tf file.tar file1.txt file2.txt file3.txt file4.txt file2.txt [rootnode1 Desktop]# 4.2.7.从归档中提取指定文件或全部文件 [rootnode1 test]# tar -tf file.tar file1.txt file2.txt file3.txt file4.txt file2.txt [rootnode1 test]# tar -xvf file.tar file3.txt file3.txt [rootnode1 test]# ll total 1287384 -rw-r--r--. 1 root root 219712350 May 13 22:21 file3.txt -rw-r--r--. 1 root root 1098567680 May 13 23:48 file.tar [rootnode1 test]# tar -xvf file.tar file1.txt file2.txt file3.txt file4.txt file2.txt [rootnode1 test]# ll total 1931076 -rw-r--r--. 1 root root 219712350 May 13 22:21 file1.txt -rw-r--r--. 1 root root 219712359 May 13 23:46 file2.txt -rw-r--r--. 1 root root 219712350 May 13 22:21 file3.txt -rw-r--r--. 1 root root 219712350 May 13 22:21 file4.txt -rw-r--r--. 1 root root 1098567680 May 13 23:48 file.tar [rootnode1 test]# 4.3. 操作修饰符 4.3.1.是否检查设备 [rootnode1 test]# tar --check-device -uvf file.tar file1.txt # 更新替换追加 file1.txt [rootnode1 test]# vi file1.txt ## 更新文件 [rootnode1 test]# tar --no-check-device -uvf file.tar file1.txt # 更新替换追加 file1.txt [rootnode1 test]# 4.3.2.全量备份与增量备份 [rootnode1 Desktop]# tar -g snapshot.file -cvf file.full.txt.tar file[1-4].txt # 全量备份生产快照文件snapshot.file file1.txt file2.txt file3.txt file4.txt [rootnode1 Desktop]# cat snapshot.file GNU tar-1.26-2 1747152665332697702[rootnode1 Desktop]# vi file3.txt # 更新文件 [rootnode1 Desktop]# tar -g snapshot.file -cvf file.inc.txt.tar file[1-4].txt # 增量备份更新快照文件snapshot.file file3.txt [rootnode1 Desktop]# cat snapshot.file GNU tar-1.26-2 1747152815368262961[rootnode1 Desktop]# 4.3.3.全量增量备份级别指定 [rootnode1 Desktop]# tar --level0 -g snapshot.file -cvf file.full.txt.tar file[1-4].txt file1.txt file2.txt file3.txt file4.txt [rootnode1 Desktop]# cat snapshot.file GNU tar-1.26-2 1747154213825223342[rootnode1 Desktop]# vi file2.txt [rootnode1 Desktop]# tar --level1 -g snapshot.file -cvf file.inc.txt.tar file[1-4].txt file2.txt [rootnode1 Desktop]# cat snapshot.file GNU tar-1.26-2 1747154260428040570[rootnode1 Desktop]# 4.3.4.归档中多版本相同名称文件处理指定的文件 [rootnode1 Desktop]# tar -tf file.tar file5.txt file6.txt file5.txt [rootnode1 Desktop]# tar --delete -f file.tar --occurrence2 file5.txt # 指定删除第2个file5.txt [rootnode1 Desktop]# tar -tf file.tar file5.txt file6.txt [rootnode1 Desktop]# ---------------------------------------------------------- [rootnode1 Desktop]# tar -tf file.tar file5.txt file6.txt file5.txt [rootnode1 Desktop]# tar --delete -f file.tar --occurrence1 file5.txt # 指定删除第1个file5.txt [rootnode1 Desktop]# tar -tf file.tar file6.txt file5.txt [rootnode1 Desktop]# 4.3.5.稀疏文件的归档 [rootnode1 Desktop]# qemu-img create -f raw file8.txt 2G # 创建一个稀疏文件 Formatting file8.txt, fmtraw size2147483648 [rootnode1 Desktop]# ll file8.txt -rw-r--r--. 1 root root 2147483648 May 14 01:49 file8.txt [rootnode1 Desktop]# ll file8.txt -h # 稀疏文件ls -h查看ll -h查看大小显示比较大 -rw-r--r--. 1 root root 2.0G May 14 01:49 file8.txt [rootnode1 Desktop]# du -sh file8.txt # 使用du -sh查看就很小 0 file8.txt [rootnode1 Desktop]# [rootnode1 Desktop]# tar -cvf file8.txt.tar file8.txt # 普通归档文件与ls -h的结果接近 file8.txt [rootnode1 Desktop]# tar -Scvf file8.txt.1.tar file8.txt # 稀疏归档与du -sh的结果接近 file8.txt [rootnode1 Desktop]# ll -h file8* -rw-r--r--. 1 root root 2.0G May 14 01:49 file8.txt -rw-r--r--. 1 root root 10K May 14 01:51 file8.txt.1.tar -rw-r--r--. 1 root root 2.1G May 14 01:50 file8.txt.tar [rootnode1 Desktop]# 4.4.输入控制覆盖寄存器 4.4.1.提取归档时是否替换系统已存在文件 [rootnode1 test]# ll total 1072832 -rw-r--r--. 1 root root 219712350 May 13 22:21 file1.txt -rw-r--r--. 1 root root 28 May 14 01:24 file5.txt -rw-r--r--. 1 root root 20 May 14 00:45 file6.txt -rw-r--r--. 1 root root 878858240 May 14 02:00 file.tar [rootnode1 test]# tar -tf file.tar file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt [rootnode1 test]# tar -xvf file.tar # 提取归档时替换系统已存在文件 file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt [rootnode1 test]# ll total 1716524 -rw-r--r--. 1 root root 219712350 May 13 22:21 file1.txt -rw-r--r--. 1 root root 219712363 May 14 00:37 file2.txt -rw-r--r--. 1 root root 219712372 May 14 00:13 file3.txt -rw-r--r--. 1 root root 219712350 May 13 22:21 file4.txt -rw-r--r--. 1 root root 28 May 14 01:24 file5.txt -rw-r--r--. 1 root root 20 May 14 00:45 file6.txt -rw-r--r--. 1 root root 878858240 May 14 02:00 file.tar [rootnode1 test]# ---------------------------------------------------------- [rootnode1 test]# ll total 1072832 -rw-r--r--. 1 root root 219712350 May 13 22:21 file1.txt -rw-r--r--. 1 root root 28 May 14 01:24 file5.txt -rw-r--r--. 1 root root 20 May 14 00:45 file6.txt -rw-r--r--. 1 root root 878858240 May 14 02:00 file.tar [rootnode1 test]# tar -kxvf file.tar # 提取归档时不替换系统已存在文件视其为错误 file1.txt tar: file1.txt: Cannot open: File exists file2.txt file3.txt file4.txt file5.txt tar: file5.txt: Cannot open: File exists file6.txt tar: file6.txt: Cannot open: File exists tar: Exiting with failure status due to previous errors [rootnode1 test]# ll total 1716524 -rw-r--r--. 1 root root 219712350 May 13 22:21 file1.txt -rw-r--r--. 1 root root 219712363 May 14 00:37 file2.txt -rw-r--r--. 1 root root 219712372 May 14 00:13 file3.txt -rw-r--r--. 1 root root 219712350 May 13 22:21 file4.txt -rw-r--r--. 1 root root 28 May 14 01:24 file5.txt -rw-r--r--. 1 root root 20 May 14 00:45 file6.txt -rw-r--r--. 1 root root 878858240 May 14 02:00 file.tar 4.4.2.是否覆盖新文件 [rootnode1 test]# ll total 858264 -rw-r--r--. 1 root root 219712350 May 13 22:21 file1.txt -rw-r--r--. 1 root root 219712363 May 14 00:37 file2.txt -rw-r--r--. 1 root root 219712372 May 14 00:13 file3.txt -rw-r--r--. 1 root root 219712350 May 13 22:21 file4.txt -rw-r--r--. 1 root root 24 May 14 02:28 file5.txt -rw-r--r--. 1 root root 20 May 14 00:45 file6.txt [rootnode1 test]# tar -cvf file.tar file[1-6].txt file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt [rootnode1 test]# vi file5.txt # 更新文件 [rootnode1 test]# tar -xvf file.tar # 默认提取归档是覆盖系统上已存在的文件 file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt [rootnode1 test]# ---------------------------------------------------------- [rootnode1 test]# ll total 1716524 drwxr-xr-x. 2 root root 124 May 14 04:43 dir1 -rw-r--r--. 1 root root 219712353 May 14 04:43 file1.txt -rw-r--r--. 1 root root 219712363 May 14 04:43 file2.txt -rw-r--r--. 1 root root 219712391 May 14 04:43 file3.txt -rw-r--r--. 1 root root 219712350 May 14 04:43 file4.txt -rw-r--r--. 1 root root 72 May 14 04:43 file5.txt -rw-r--r--. 1 root root 20 May 14 04:43 file6.txt -rw-r--r--. 1 root root 878858240 May 14 04:43 file.tar [rootnode1 test]# vi file5.txt # 编辑文件使得成为新的版本文件 [rootnode1 test]# rm -rf file.tar [rootnode1 test]# tar -cvf file.tar file[1-6].txt # 重新归档打包 file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt [rootnode1 test]# cp file.tar dir1/ # 覆盖之前的归档文件 cp: overwrite ‘dir1/file.tar’? yes [rootnode1 test]# cd dir1/ [rootnode1 dir1]# ll # 查看之前归档提取的文件下面添加--keep-newer-files参数提取 total 1716524 -rw-r--r--. 1 root root 219712353 May 14 04:43 file1.txt -rw-r--r--. 1 root root 219712363 May 14 04:43 file2.txt -rw-r--r--. 1 root root 219712391 May 14 04:43 file3.txt -rw-r--r--. 1 root root 219712350 May 14 04:43 file4.txt -rw-r--r--. 1 root root 72 May 14 04:43 file5.txt -rw-r--r--. 1 root root 20 May 14 04:43 file6.txt -rw-r--r--. 1 root root 878858240 May 14 04:43 file.tar [rootnode1 dir1]# tar --keep-newer-files -xvf file.tar # 归档中新版本文件会被提取并替换系统中对应的现有文件归档中其他旧版本或者相同版本不会被提取 file1.txt tar: Current file1.txt is newer or same age file2.txt tar: Current file2.txt is newer or same age file3.txt tar: Current file3.txt is newer or same age file4.txt tar: Current file4.txt is newer or same age file5.txt file6.txt tar: Current file6.txt is newer or same age [rootnode1 dir1]# 4.4.3.保留目录元数据作用域 [rootnode1 dir2]# chmod -R 777 dir1 [rootnode1 dir2]# chown -R qwer:qwer dir1 [rootnode1 dir2]# ll total 12 drwxrwxrwx. 4 qwer qwer 49 May 14 13:32 dir1 -rw-r--r--. 1 root root 10240 May 14 05:01 dir1.tar [rootnode1 dir2]# ll dir1 total 4 drwxrwxrwx. 3 qwer qwer 36 May 14 13:32 dir11 drwxrwxrwx. 3 qwer qwer 36 May 14 13:32 dir12 -rwxrwxrwx. 1 qwer qwer 17 May 14 04:49 file1.txt [rootnode1 dir2]# ll dir1/dir11 total 4 drwxrwxrwx. 2 qwer qwer 6 May 14 05:00 dir21 # 修改了用户和读写执行权限 -rwxrwxrwx. 1 qwer qwer 15 May 14 04:48 file1.txt [rootnode1 dir2]# [rootnode1 dir2]# tar --no-overwrite-dir -xvf dir1.tar # 之前解压过修改权限后使用--no-overwrite-dir参数再解压 dir1/ dir1/dir11/ dir1/dir11/file1.txt dir1/dir11/dir21/ dir1/dir12/ dir1/dir12/file1.txt dir1/dir12/dir22/ dir1/file1.txt [rootnode1 dir2]# ll total 12 drwxrwxrwx. 4 qwer qwer 49 May 14 13:33 dir1 # 已经存在的非最内层目录保留了元数据 -rw-r--r--. 1 root root 10240 May 14 05:01 dir1.tar [rootnode1 dir2]# ll dir1 total 4 drwxrwxrwx. 3 qwer qwer 36 May 14 13:33 dir11 # 已经存在的非最内层目录保留了元数据 drwxrwxrwx. 3 qwer qwer 36 May 14 13:33 dir12 # 已经存在的非最内层目录保留了元数据 -rw-r--r--. 1 root root 17 May 14 04:49 file1.txt # 仅对目录有效果对文件无效果 [rootnode1 dir2]# ll dir1/dir11 total 4 drwxr-xr-x. 2 root root 6 May 14 05:00 dir21 # 已经存在的最内层目录没有保留元数据 -rw-r--r--. 1 root root 15 May 14 04:48 file1.txt [rootnode1 dir2]# 4.4.4.归档提取覆盖系统上现有文件 [rootnode1 dir1]# cat file1.txt aaaaaaaa bbbbbbbb cccccccc [rootnode1 dir1]# tar -cvf file1.tar file1.txt file1.txt [rootnode1 dir1]# ll total 16 -rw-r--r--. 1 root root 10240 May 14 13:54 file1.tar -rw-r--r--. 1 root root 27 May 14 13:54 file1.txt [rootnode1 dir1]# vi file1.txt [rootnode1 dir1]# cat file1.txt # 文件修改后保留两行 aaaaaaaa bbbbbbbb [rootnode1 dir1]# tar --overwrite -xvf file1.tar # 覆盖提取文件 file1.txt [rootnode1 dir1]# cat file1.txt # 覆盖后文件还是原始的三行 aaaaaaaa bbbbbbbb cccccccc [rootnode1 dir1]# 4.4.5.文件添加到归档后删除文件同样适用于目录归档 [rootnode1 dir1]# ll total 4 -rw-r--r--. 1 root root 27 May 14 13:54 file1.txt [rootnode1 dir1]# tar --remove-files -cvf file1.tar file1.txt file1.txt [rootnode1 dir1]# ll total 12 -rw-r--r--. 1 root root 10240 May 14 14:10 file1.tar [rootnode1 dir1]# 4.4.6.提取归档时先删除对应内容(删除目录时提升目录非空错误) [rootnode1 dir2]# ll total 12 drwxr-xr-x. 4 root root 49 May 14 04:49 dir1 -rw-r--r--. 1 root root 10240 May 14 05:01 dir1.tar [rootnode1 dir2]# tar -Uxvf dir1.tar dir1/ tar: dir1: Cannot unlink: Directory not empty dir1/dir11/ tar: dir1/dir11: Cannot unlink: Directory not empty dir1/dir11/file1.txt dir1/dir11/dir21/ dir1/dir12/ tar: dir1/dir12: Cannot unlink: Directory not empty dir1/dir12/file1.txt dir1/dir12/dir22/ dir1/file1.txt tar: Exiting with failure status due to previous errors [rootnode1 dir2]# 4.4.7.写入归档后验证归档内文件目录 [rootnode1 dir2]# tar -Wcvf dir2.tar dir1/ dir1/ dir1/dir11/ dir1/dir11/file1.txt dir1/dir11/dir21/ dir1/dir12/ dir1/dir12/file1.txt dir1/dir12/dir22/ dir1/file1.txt Verify dir1/ Verify dir1/dir11/ Verify dir1/dir11/file1.txt Verify dir1/dir11/dir21/ Verify dir1/dir12/ Verify dir1/dir12/file1.txt Verify dir1/dir12/dir22/ Verify dir1/file1.txt [rootnode1 dir2]# 4.5.选择输出流 4.5.1.将归档中的文件提取到标准输出 [rootnode1 dir1]# tar -Oxvf file1.tar file1.txt aaaaaaaa bbbbbbbb cccccccc [rootnode1 dir1]# ll total 12 -rw-r--r--. 1 root root 10240 May 14 14:10 file1.tar [rootnode1 dir1]# 4.5.2.将归档中文件提取到指定命令进行处理 [rootnode1 dir1]# tar -xvf file1.tar --to-commandcat file1.txt aaaaaaaa bbbbbbbb cccccccc [rootnode1 dir1]# ll total 12 -rw-r--r--. 1 root root 10240 May 14 14:10 file1.tar [rootnode1 dir1]# tar -xvf file1.tar --to-commandcat | grep aaa file1.txt aaaaaaaa [rootnode1 dir1]# 4.6.文件属性的处理 4.6.1.保留归档中文件访问时间无效果 [rootnode1 dir1]# stat file1.txt File: ‘file1.txt’Size: 219712350 Blocks: 429128 IO Block: 4096 regular file Device: 803h/2051d Inode: 35033734 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2025-05-14 16:06:13.430271347 0800 Modify: 2025-05-14 16:03:46.000000000 0800 Change: 2025-05-14 16:07:43.513273581 0800Birth: - [rootnode1 dir1]# tar --atime-preservereplace -cvf file1.1.tar file1.txt file1.txt [rootnode1 dir1]# tar --atime-preservereplace -xvf file1.1.tar file1.txt [rootnode1 dir1]# stat file1.txt File: ‘file1.txt’Size: 219712350 Blocks: 429128 IO Block: 4096 regular file Device: 803h/2051d Inode: 35033734 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2025-05-14 16:08:02.103274042 0800 # 访问时间改变了无效果 Modify: 2025-05-14 16:03:46.000000000 0800 Change: 2025-05-14 16:08:02.258274045 0800Birth: - [rootnode1 dir1]# 4.6.2.归档时指定组权限 [rootnode1 dir2]# tar --groupqwer -cvf dir3.tar dir1/ # 归档时指定组权限归档 dir1/ dir1/dir11/ dir1/dir11/dir21/ dir1/dir11/file1.txt dir1/dir12/ dir1/dir12/dir22/ dir1/dir12/file1.txt dir1/file1.txt [rootnode1 dir2]# ll total 36 drwxr-xr-x. 4 root root 49 May 14 04:49 dir1 # dir1 是root组权限 -rw-r--r--. 1 root root 10240 May 14 05:01 dir1.tar -rw-r--r--. 1 root root 10240 May 14 14:19 dir2.tar -rw-r--r--. 1 root root 10240 May 14 16:53 dir3.tar [rootnode1 dir2]# [rootnode1 dir2]# [rootnode1 dir2]# tar --groupqwer -xvf dir3.tar # 提取归档后的目录文件组权限就会改变 dir1/ dir1/dir11/ dir1/dir11/dir21/ dir1/dir11/file1.txt dir1/dir12/ dir1/dir12/dir22/ dir1/dir12/file1.txt dir1/file1.txt [rootnode1 dir2]# ll total 36 drwxr-xr-x. 4 root qwer 49 May 14 04:49 dir1 -rw-r--r--. 1 root root 10240 May 14 05:01 dir1.tar -rw-r--r--. 1 root root 10240 May 14 14:19 dir2.tar -rw-r--r--. 1 root root 10240 May 14 16:53 dir3.tar [rootnode1 dir2]# 4.6.3.创建归档时修改Modify时间(mtime) [rootnode1 dir1]# stat file1.txt File: ‘file1.txt’Size: 41 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 35033735 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2025-05-14 16:12:36.390280843 0800 Modify: 2025-05-14 16:10:53.000000000 0800 # 文件原来的mtime时间 Change: 2025-05-14 16:12:36.390280843 0800Birth: - [rootnode1 dir1]# tar --mtime2025-05-14 16:01:01 -cvf file1.tar file1.txt file1.txt [rootnode1 dir1]# tar -xvf file1.tar file1.txt [rootnode1 dir1]# stat file1.txt File: ‘file1.txt’Size: 41 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 35033735 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2025-05-14 17:27:39.489392499 0800 Modify: 2025-05-14 16:01:01.000000000 0800 # 归档提取后mtime时间是创建归档时指定的时间 Change: 2025-05-14 17:27:39.489392499 0800Birth: - [rootnode1 dir1]# 4.6.4.提取归档时不保留文件的mtime时间 [rootnode1 dir1]# stat file1.txt File: ‘file1.txt’Size: 41 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 35033735 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2025-05-14 17:33:54.282401793 0800 Modify: 2025-05-14 16:01:01.000000000 0800 # 正常归档提取的mtime时间 Change: 2025-05-14 17:33:54.282401793 0800Birth: - [rootnode1 dir1]# tar -mxvf file1.tar file1.txt [rootnode1 dir1]# stat file1.txt File: ‘file1.txt’Size: 41 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 35033735 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2025-05-14 17:34:26.442402590 0800 Modify: 2025-05-14 17:34:26.442402590 0800 # 指定-m参数归档提取的mtime时间 Change: 2025-05-14 17:34:26.442402590 0800Birth: - [rootnode1 dir1]# 4.6.5.提取归档文件时是否保留归档中文件原有的拥有者(owner)、用户组、用户 [qwernode1 dir1]$ ll dir1/ total 4 drwxr-xr-x. 3 qwer qwer 36 May 14 05:00 dir11 drwxr-xr-x. 3 qwer qwer 36 May 14 05:00 dir12 -rw-r--r--. 1 qwer qwer 17 May 14 04:49 file1.txt [qwernode1 dir1]$ tar -cvf dir1.tar dir1/ # 普通用户压缩目录整个目录的用户组和用户权限都是qwer用户 dir1/ dir1/dir11/ dir1/dir11/dir21/ dir1/dir11/file1.txt dir1/dir12/ dir1/dir12/dir22/ dir1/dir12/file1.txt dir1/file1.txt [qwernode1 dir1]$ ----------------------------------------------------- [rootnode1 opt]# tar --no-same-owner -xvf dir1.tar # 提取归档后文件拥有者(owner)为当前用户与归档中文件拥有者(owner)不同 dir1/ dir1/dir11/ dir1/dir11/dir21/ dir1/dir11/file1.txt dir1/dir12/ dir1/dir12/dir22/ dir1/dir12/file1.txt dir1/file1.txt [rootnode1 opt]# ll dir1 total 4 drwxr-xr-x. 3 root root 36 May 14 05:00 dir11 drwxr-xr-x. 3 root root 36 May 14 05:00 dir12 -rw-r--r--. 1 root root 17 May 14 04:49 file1.txt [rootnode1 opt]# ----------------------------------------------------- [rootnode1 opt]# tar --same-owner -xvf dir1.tar # 提取归档后文件属性与归档中的文件拥有者(owner)相同 dir1/ dir1/dir11/ dir1/dir11/dir21/ dir1/dir11/file1.txt dir1/dir12/ dir1/dir12/dir22/ dir1/dir12/file1.txt dir1/file1.txt [rootnode1 opt]# ll dir1 total 4 drwxr-xr-x. 3 qwer qwer 36 May 14 05:00 dir11 drwxr-xr-x. 3 qwer qwer 36 May 14 05:00 dir12 -rw-r--r--. 1 qwer qwer 17 May 14 04:49 file1.txt [rootnode1 opt]# ----------------------------------------------------- [rootnode1 opt]# tar --no-same-permissions -xvf dir1.tar # 提取归档后文件属性保留归档前的用户组和用户权限 dir1/ dir1/dir11/ dir1/dir11/dir21/ dir1/dir11/file1.txt dir1/dir12/ dir1/dir12/dir22/ dir1/dir12/file1.txt dir1/file1.txt [rootnode1 opt]# ll dir1/ total 4 drwxr-xr-x. 3 qwer qwer 36 May 14 05:00 dir11 drwxr-xr-x. 3 qwer qwer 36 May 14 05:00 dir12 -rw-r--r--. 1 qwer qwer 17 May 14 04:49 file1.txt [rootnode1 opt]# 4.6.6.归档时用户/组权限以数字方式保留提取归档时显示数字对应的用户(与之前的用户可能不一样)或者显示数字(数字对应的用户不存在时) [rootnode1 dir1]# cat /etc/passwd ... ... u1:x:1001:1001::/home/u1:/bin/bash [rootnode1 opt]# ll total 0 drwxr-xr-x. 4 u1 u1 49 May 14 04:49 dir1 ... ... [rootnode1 opt]# tar --numeric-owner -cvf dir1.tar dir1/ # 归档时指定用户/组权限使用数字方式保留 dir1/ dir1/dir11/ dir1/dir11/dir21/ dir1/dir11/file1.txt dir1/dir12/ dir1/dir12/dir22/ dir1/dir12/file1.txt dir1/file1.txt [rootnode1 opt]# [rootnode1 opt]# useradd u2 [rootnode1 opt]# useradd u3 [rootnode1 opt]# userdel u1 [rootnode1 opt]# useradd u1 [rootnode1 dir1]# cat /etc/passwd ... ... u3:x:1002:1002::/home/u2:/bin/bash u4:x:1003:1003::/home/u3:/bin/bash u1:x:1004:1004::/home/u1:/bin/bash [rootnode1 opt]# tar --numeric-owner -xvf dir1.tar # tar -xvf dir1.tar # 以数字保留归档中文件的用户/组权限解压后如果数字对应的用户不存在就显示数字 dir1/ dir1/dir11/ dir1/dir11/dir21/ dir1/dir11/file1.txt dir1/dir12/ dir1/dir12/dir22/ dir1/dir12/file1.txt dir1/file1.txt [rootnode1 opt]# ll total 12 drwxr-xr-x. 4 1001 1001 49 May 14 04:49 dir1 ... ... [rootnode1 opt]# 4.6.7.创建归档时指定用户权限 [rootnode1 dir1]# ll total 4 -rw-r--r--. 1 root root 41 May 14 17:34 file1.txt [rootnode1 dir1]# tar --ownerqwer -cvf file1.tar file1.txt file1.txt [rootnode1 dir1]# ll total 16 -rw-r--r--. 1 root root 10240 May 14 18:35 file1.tar -rw-r--r--. 1 root root 41 May 14 17:34 file1.txt [rootnode1 dir1]# tar -xvf file1.tar file1.txt [rootnode1 dir1]# ll total 16 -rw-r--r--. 1 root root 10240 May 14 18:35 file1.tar -rw-r--r--. 1 qwer root 41 May 14 17:34 file1.txt # 提取归档后文件为创建归档时指定的用户权限 [rootnode1 dir1]# 4.7.设备选择和切换 4.7.1.带有冒号的归档文件视为本地文件 [rootnode1 dir1]# tar -cvf file:1.tar file1.txt # 归档名称定义带有冒号执行会卡住Ctrlc强制退出 ^C [rootnode1 dir1]# tar --force-local -cvf file:1.tar file1.txt # 强制视为本地文件 file1.txt [rootnode1 dir1]# ll total 16 -rw-r--r--. 1 root root 10240 May 14 19:19 file:1.tar -rw-r--r--. 1 root root 20 May 14 19:18 file1.txt [rootnode1 dir1]# 4.8.档案格式选择 4.8.1.给归档设置一个标签 [rootnode1 dir1]# tar -cvf file1.tar file1.txt file1.txt [rootnode1 dir1]# tar -V This is label -cvf file1_1.tar file1.txt This is label file1.txt [rootnode1 dir1]# tar -tf file1.tar file1.txt [rootnode1 dir1]# tar -tf file1_1.tar This is label # 元数据中可以看到归档是自定义的标签 file1.txt [rootnode1 dir1]# 4.9.压缩选项  4.9.1.按照归档文件的后缀名进行归档或者压缩 [rootnode1 dir1]# tar -cvf file1.1.tar file1.txt file1.txt [rootnode1 dir1]# tar -zcvf file1.2.tar file1.txt file1.txt [rootnode1 dir1]# tar -acvf file1.3.tar file1.txt file1.txt [rootnode1 dir1]# tar -acvf file1.4.tar.gz file1.txt file1.txt [rootnode1 dir1]# ll total 644964 -rw-r--r--. 1 root root 219719680 May 15 19:51 file1.1.tar -rw-r--r--. 1 root root 639173 May 15 19:51 file1.2.tar.gz -rw-r--r--. 1 root root 219719680 May 15 19:53 file1.3.tar -rw-r--r--. 1 root root 639173 May 15 19:53 file1.4.tar.gz -rw-r--r--. 1 root root 219712350 May 15 19:50 file1.txt [rootnode1 dir1]# 4.9.2.选择压缩方式进行归档 [rootnode1 dir1]# tar -zcvf dir2.tar.gz dir2/ dir2/ dir2/file4.txt dir2/file56.tat dir2/file5.txt dir2/file6.txt dir2/file7.txt [rootnode1 dir1]# tar -jcvf dir2.tar.bz2 dir2/ dir2/ dir2/file4.txt dir2/file56.tat dir2/file5.txt dir2/file6.txt dir2/file7.txt [rootnode1 dir1]# tar -Jcvf dir2.tar.xz dir2/ dir2/ dir2/file4.txt dir2/file56.tat dir2/file5.txt dir2/file6.txt dir2/file7.txt [rootnode1 dir1]# tar --lzip -cvf dir2.tar.lz dir2/ tar (child): lzip: Cannot exec: No such file or directory tar (child): Error is not recoverable: exiting now dir2/ dir2/file4.txt [rootnode1 dir1]# tar --lzma -cvf dir2.tar.lzma dir2/ tar (child): lzma: Cannot execdir2/ dir2/file4.txt : No such file or directory tar (child): Error is not recoverable: exiting now [rootnode1 dir1]# [rootnode1 dir1]# tar --lzop -cvf dir2.tar.lzop dir2/ dir2/ dir2/file4.txt dir2/file56.tat dir2/file5.txt dir2/file6.txt dir2/file7.txt [rootnode1 dir1]# tar -Zcvf dir2.tar.Z dir2/ dir2/ dir2/file4.txt dir2/file56.tat dir2/file5.txt dir2/file6.txt dir2/file7.txt [rootnode1 dir1]# [rootnode1 dir1]# ll total 2388 drwxr-xr-x. 2 root root 92 May 15 20:31 dir2 -rw-r--r--. 1 root root 10782 May 15 20:32 dir2.tar.bz2 -rw-r--r--. 1 root root 639568 May 15 20:31 dir2.tar.gz -rw-r--r--. 1 root root 0 May 15 20:46 dir2.tar.lz # 执行报错压缩归档文件大小为0 -rw-r--r--. 1 root root 0 May 15 20:46 dir2.tar.lzma # 执行报错压缩归档文件大小为0 -rw-r--r--. 1 root root 1100615 May 15 20:47 dir2.tar.lzop -rw-r--r--. 1 root root 32500 May 15 20:40 dir2.tar.xz -rw-r--r--. 1 root root 651647 May 15 20:47 dir2.tar.Z [rootnode1 dir1]# # 可更具其大小判断压缩比 4.10.本地文件选择 4.10.1.系统上如已经存在可选择备份(使用数字备份) [rootnode1 dir1]# ll total 24 -rw-r--r--. 1 root root 14 May 15 20:58 file1.txt -rw-r--r--. 1 root root 14 May 15 20:58 file2.txt -rw-r--r--. 1 root root 14 May 15 20:58 file3.txt -rw-r--r--. 1 root root 10240 May 15 21:49 file.tar [rootnode1 dir1]# tar -tf file.tar file1.txt file2.txt file3.txt [rootnode1 dir1]# tar --backupt -xvf file.tar file1.txt Renaming file1.txt to file1.txt.~1~ file2.txt Renaming file2.txt to file2.txt.~1~ file3.txt Renaming file3.txt to file3.txt.~1~ [rootnode1 dir1]# ll total 36 -rw-r--r--. 1 root root 14 May 15 20:58 file1.txt -rw-r--r--. 1 root root 14 May 15 20:58 file1.txt.~1~ # 已存在文件进行备份使用数字后缀 -rw-r--r--. 1 root root 14 May 15 20:58 file2.txt -rw-r--r--. 1 root root 14 May 15 20:58 file2.txt.~1~ -rw-r--r--. 1 root root 14 May 15 20:58 file3.txt -rw-r--r--. 1 root root 14 May 15 20:58 file3.txt.~1~ -rw-r--r--. 1 root root 10240 May 15 21:49 file.tar [rootnode1 dir1]# 4.10.2.提取归档内容到指定的目录(默认提取是当前目录) [rootnode1 dir1]# ll dir2/ total 0 [rootnode1 dir1]# tar -C dir2/ -xvf file.tar file1.txt file2.txt file3.txt [rootnode1 dir1]# ll dir2/ total 12 -rw-r--r--. 1 root root 14 May 15 20:58 file1.txt -rw-r--r--. 1 root root 14 May 15 20:58 file2.txt -rw-r--r--. 1 root root 14 May 15 20:58 file3.txt [rootnode1 dir1]# 4.10.3.提取/创建归档时排除指定的文件 [rootnode1 dir1]# ll total 12 -rw-r--r--. 1 root root 14 May 15 20:58 file1.txt -rw-r--r--. 1 root root 14 May 15 20:58 file2.txt -rw-r--r--. 1 root root 14 May 15 20:58 file3.txt [rootnode1 dir1]# tar --excludefile2.txt -cvf file.tar file*.txt file1.txt file3.txt [rootnode1 dir1]# ------------------------------------------------------------------ [rootnode1 dir1]# ll dir2/ total 0 [rootnode1 dir1]# tar -C dir2/ --excludefile2.txt -xvf file.tar file1.txt file3.txt [rootnode1 dir1]# ll dir2/ total 8 -rw-r--r--. 1 root root 14 May 15 20:58 file1.txt -rw-r--r--. 1 root root 14 May 15 20:58 file3.txt [rootnode1 dir1]# 4.10.4.压缩时是否保留符号链接(软链接/硬链接) [rootnode1 Desktop]# ll dir1 total 8 lrwxrwxrwx. 1 root root 5 May 16 04:41 dir - dir2/ drwxr-xr-x. 2 root root 6 May 16 04:40 dir2 drwxr-xr-x. 2 root root 6 May 16 04:41 dir3 -rw-r--r--. 1 root root 12 May 16 04:40 file1.txt -rw-r--r--. 1 root root 58 May 16 04:40 file2.txt lrwxrwxrwx. 1 root root 9 May 16 04:41 file.txt - file1.txt [rootnode1 Desktop]# tar --dereference -cvf dir1.tar dir1/ dir1/ dir1/file1.txt dir1/file2.txt dir1/dir2/ dir1/dir3/ dir1/file.txt dir1/dir/ [rootnode1 Desktop]# tar -tvf dir1.tar drwxr-xr-x root/root 0 2025-05-16 04:41 dir1/ -rw-r--r-- root/root 12 2025-05-16 04:40 dir1/file1.txt -rw-r--r-- root/root 58 2025-05-16 04:40 dir1/file2.txt drwxr-xr-x root/root 0 2025-05-16 04:40 dir1/dir2/ drwxr-xr-x root/root 0 2025-05-16 04:41 dir1/dir3/ hrw-r--r-- root/root 0 2025-05-16 04:40 dir1/file.txt link to dir1/file1.txt drwxr-xr-x root/root 0 2025-05-16 04:40 dir1/dir/ [rootnode1 Desktop]# rm -rf dir1/ [rootnode1 Desktop]# tar xvf dir1.tar dir1/ dir1/file1.txt dir1/file2.txt dir1/dir2/ dir1/dir3/ dir1/file.txt dir1/dir/ [rootnode1 Desktop]# ll dir1 total 12 drwxr-xr-x. 2 root root 6 May 16 04:40 dir drwxr-xr-x. 2 root root 6 May 16 04:40 dir2 drwxr-xr-x. 2 root root 6 May 16 04:41 dir3 -rw-r--r--. 2 root root 12 May 16 04:40 file1.txt -rw-r--r--. 1 root root 58 May 16 04:40 file2.txt -rw-r--r--. 2 root root 12 May 16 04:40 file.txt [rootnode1 Desktop]# -------------------------------------------------- [rootnode1 dir1]# ln file1.txt file.txt [rootnode1 dir1]# ll total 12 drwxr-xr-x. 2 root root 6 May 16 04:40 dir2 drwxr-xr-x. 2 root root 6 May 16 04:41 dir3 -rw-r--r--. 2 root root 12 May 16 04:40 file1.txt -rw-r--r--. 1 root root 58 May 16 04:40 file2.txt -rw-r--r--. 2 root root 12 May 16 04:40 file.txt [rootnode1 dir1]# cd .. [rootnode1 Desktop]# tar --hard-dereference -cvf dir1.tar dir1/ dir1/ dir1/file1.txt dir1/file2.txt dir1/dir2/ dir1/dir3/ dir1/file.txt [rootnode1 Desktop]# [rootnode1 Desktop]# tar -xvf dir1.tar dir1/ dir1/file1.txt dir1/file2.txt dir1/dir2/ dir1/dir3/ dir1/file.txt [rootnode1 Desktop]# ll dir1 total 12 drwxr-xr-x. 2 root root 6 May 16 04:40 dir2 drwxr-xr-x. 2 root root 6 May 16 04:41 dir3 -rw-r--r--. 1 root root 20 May 16 04:52 file1.txt -rw-r--r--. 1 root root 58 May 16 04:40 file2.txt -rw-r--r--. 1 root root 20 May 16 04:52 file.txt [rootnode1 Desktop]# vi dir1/file.txt [rootnode1 Desktop]# cat dir1/file.txt asjdlfjaldk iaaaaaa ibbbbbb [rootnode1 Desktop]# cat dir1/file1.txt # 已经不是硬链接硬链接修改一个另一个也会更新 asjdlfjaldk iaaaaaa [rootnode1 Desktop]# 4.10.5.从指定的文件开始解压 [rootnode1 Desktop]# tar -tf dir1.2.tar.gz dir1/ dir1/file1.txt dir1/file2.txt dir1/file3.txt dir1/file4.txt dir1/file56.tat dir1/file5.txt dir1/file6.txt dir1/file7.txt dir1/file8.txt [rootnode1 Desktop]# tar -zxvf dir1.2.tar.gz -K dir1/file56.tat dir1/file56.tat dir1/file5.txt dir1/file6.txt dir1/file7.txt dir1/file8.txt [rootnode1 Desktop]# ll dir1 total 2097176 -rw-r--r--. 1 root root 10240 May 15 20:02 file56.tat -rw-r--r--. 1 root root 28 May 15 20:02 file5.txt -rw-r--r--. 1 root root 20 May 15 20:02 file6.txt -rw-r--r--. 1 root root 2390 May 15 20:02 file7.txt -rw-r--r--. 1 root root 2147483648 May 15 20:02 file8.txt [rootnode1 Desktop]# 4.10.6.仅归档某一个时间及其之后时间的的文件(s时间包括mtime、ctime) [rootnode1 Desktop]# stat dir1/* | grep Modify Modify: 2025-05-15 20:02:15.000000000 0800 Modify: 2025-05-15 20:02:15.000000000 0800 Modify: 2025-05-15 20:02:15.000000000 0800 Modify: 2025-05-16 05:14:29.701865574 0800 Modify: 2025-05-16 05:12:46.702869002 0800 [rootnode1 Desktop]# tar --newer-mtime2025-05-16 00:00:00 -cvf dir1.tar dir1/ dir1/ tar: dir1/file5.txt: file is unchanged; not dumped tar: dir1/file6.txt: file is unchanged; not dumped tar: dir1/file7.txt: file is unchanged; not dumped dir1/file8.txt dir1/file9.txt [rootnode1 Desktop]#[rootnode1 Desktop]# stat dir1/* | grep Change Change: 2025-05-16 06:00:42.509773290 0800 Change: 2025-05-16 06:00:42.509773290 0800 Change: 2025-05-16 06:00:42.509773290 0800 Change: 2025-05-16 06:01:29.106771739 0800 Change: 2025-05-16 06:01:39.172771404 0800 [rootnode1 Desktop]# [rootnode1 Desktop]# tar -N 2025-05-16 06:00:45 -cvf dir1.tar dir1/ dir1/ tar: dir1/file5.txt: file is unchanged; not dumped tar: dir1/file6.txt: file is unchanged; not dumped tar: dir1/file7.txt: file is unchanged; not dumped dir1/file8.txt dir1/file9.txt [rootnode1 Desktop]# 4.10.7.在文件中指定(-T)/排除(-X)需要提取/创建归档的文件名称 [rootnode1 dir1]# ll total 24 -rw-r--r--. 1 root root 28 May 15 20:02 file5.txt -rw-r--r--. 1 root root 20 May 15 20:02 file6.txt -rw-r--r--. 1 root root 2390 May 15 20:02 file7.txt -rw-r--r--. 1 root root 15 May 16 05:14 file8.txt -rw-r--r--. 1 root root 14 May 16 05:12 file9.txt -rw-r--r--. 1 root root 20 May 16 05:27 filelist.txt [rootnode1 dir1]# cat filelist.txt file5.txt file7.txt [rootnode1 dir1]# tar -cvf dir1.tar -T filelist.txt file5.txt file7.txt [rootnode1 dir1]# tar --no-null -cvf dir1.tar -T filelist.txt file5.txt file7.txt [rootnode1 dir1]# [rootnode1 dir1]# tar --null -cvf dir1.tar -T filelist.txt tar: file5.txt\nfile7.txt\n: Cannot stat: No such file or directory tar: Exiting with failure status due to previous errors [rootnode1 dir1]# -------------------------------------------------------- [rootnode1 dir1]# ll total 24 -rw-r--r--. 1 root root 28 May 15 20:02 file5.txt -rw-r--r--. 1 root root 20 May 15 20:02 file6.txt -rw-r--r--. 1 root root 2390 May 15 20:02 file7.txt -rw-r--r--. 1 root root 25 May 16 06:01 file8.txt -rw-r--r--. 1 root root 81 May 16 06:01 file9.txt -rw-r--r--. 1 root root 20 May 16 06:36 filelist [rootnode1 dir1]# cat filelist file6.txt file9.txt [rootnode1 dir1]# tar -X filelist -cvf file.tar file*.txt file5.txt file7.txt file8.txt [rootnode1 dir1]# 4.10.8.按照目录的层级进行归档 [rootnode1 Desktop]# ll dir1 total 20 drwxr-xr-x. 2 root root 23 May 16 05:39 dir1 drwxr-xr-x. 2 root root 23 May 16 05:39 dir2 -rw-r--r--. 1 root root 28 May 15 20:02 file5.txt -rw-r--r--. 1 root root 20 May 15 20:02 file6.txt -rw-r--r--. 1 root root 2390 May 15 20:02 file7.txt -rw-r--r--. 1 root root 15 May 16 05:14 file8.txt -rw-r--r--. 1 root root 14 May 16 05:12 file9.txt [rootnode1 Desktop]# ll dir1/dir1 total 0 -rw-r--r--. 1 root root 0 May 16 05:39 file1.txt [rootnode1 Desktop]# ll dir1/dir2 total 0 -rw-r--r--. 1 root root 0 May 16 05:39 file2.txt [rootnode1 Desktop]# [rootnode1 Desktop]# tar --no-recursion -cvf dir1.tar dir1/ # 仅归档指定的当前目录层级其内部的文件或者目录都不会归档 dir1/ # 上面指定dir1就归档该目录其下的文件目录不会归档 [rootnode1 Desktop]# tar --no-recursion -cvf dir1.tar dir1/* # 这里的dir1/*时dir1的下面一层再下一次就不会被归档 dir1/dir1/ dir1/dir2/ dir1/file5.txt dir1/file6.txt dir1/file7.txt dir1/file8.txt dir1/file9.txt [rootnode1 Desktop]# 4.10.9.带有根目录开始的目录或文件-P参数归档不会去除根目录看以下测试效果 [rootnode1 Desktop]# tar -cvPf back.tar /root/Desktop/dir1 /root/Desktop/dir1/ /root/Desktop/dir1/file5.txt /root/Desktop/dir1/file6.txt /root/Desktop/dir1/file7.txt /root/Desktop/dir1/file8.txt /root/Desktop/dir1/file9.txt [rootnode1 Desktop]# [rootnode1 Desktop]# [rootnode1 Desktop]# tar -cvf back1.tar /root/Desktop/dir1 tar: Removing leading / from member names # 没有-P参数 /root/Desktop/dir1/ /root/Desktop/dir1/file5.txt /root/Desktop/dir1/file6.txt /root/Desktop/dir1/file7.txt /root/Desktop/dir1/file8.txt /root/Desktop/dir1/file9.txt [rootnode1 Desktop]# [rootnode1 Desktop]# tar -xvPf back.tar /root/Desktop/dir1/ /root/Desktop/dir1/file5.txt /root/Desktop/dir1/file6.txt /root/Desktop/dir1/file7.txt /root/Desktop/dir1/file8.txt /root/Desktop/dir1/file9.txt [rootnode1 Desktop]# [rootnode1 Desktop]# tar -xvf back1.tar # 没有-P参数 root/Desktop/dir1/ root/Desktop/dir1/file5.txt root/Desktop/dir1/file6.txt root/Desktop/dir1/file7.txt root/Desktop/dir1/file8.txt root/Desktop/dir1/file9.txt [rootnode1 Desktop]# 4.11.文件名转换  4.11.1.指定解压的目录层级 [rootnode1 dir1]# tar --strip-components1 -xvf Desktop.tar root/Desktop/dir1/ root/Desktop/dir1/file5.txt root/Desktop/dir1/file6.txt root/Desktop/dir1/file7.txt root/Desktop/dir1/file8.txt root/Desktop/dir1/file9.txt root/Desktop/dir1/filelist root/Desktop/dir1/file.tar [rootnode1 dir1]# ll total 20 drwxr-xr-x. 3 root root 18 May 16 06:56 Desktop # 去除1层后是Desktop -rw-r--r--. 1 root root 20480 May 16 06:54 Desktop.tar [rootnode1 dir1]# [rootnode1 dir1]# tar --strip-components2 -xvf Desktop.tar root/Desktop/dir1/ root/Desktop/dir1/file5.txt root/Desktop/dir1/file6.txt root/Desktop/dir1/file7.txt root/Desktop/dir1/file8.txt root/Desktop/dir1/file9.txt root/Desktop/dir1/filelist root/Desktop/dir1/file.tar [rootnode1 dir1]# ll total 20 -rw-r--r--. 1 root root 20480 May 16 06:54 Desktop.tar drwxr-xr-x. 2 root root 123 May 16 06:36 dir1 # 去除2层后是dir1 [rootnode1 dir1]# 4.11.2.sed正则修改归档中文件的名称 [rootnode1 dir1]# ll total 12 -rw-r--r--. 1 root root 10240 May 16 06:58 file.tar [rootnode1 dir1]# tar -tf file.tar file5.txt file6.txt file7.txt file8.txt file9.txt [rootnode1 dir1]# tar -xvf file.tar --transforms/file/test/g file5.txt file6.txt file7.txt file8.txt file9.txt [rootnode1 dir1]# ll total 32 -rw-r--r--. 1 root root 10240 May 16 06:58 file.tar -rw-r--r--. 1 root root 28 May 15 20:02 test5.txt -rw-r--r--. 1 root root 20 May 15 20:02 test6.txt -rw-r--r--. 1 root root 2390 May 15 20:02 test7.txt -rw-r--r--. 1 root root 25 May 16 06:01 test8.txt -rw-r--r--. 1 root root 81 May 16 06:01 test9.txt [rootnode1 dir1]# 4.12.文件名匹配选项 4.12.1.匹配规则(忽略大小写、严格大小写、通配符、逐字符匹配) [rootnode1 dir1]# ll total 20 -rw-r--r--. 1 root root 28 May 15 20:02 test5.txt -rw-r--r--. 1 root root 20 May 15 20:02 test6.txt -rw-r--r--. 1 root root 2390 May 15 20:02 test7.txt -rw-r--r--. 1 root root 25 May 16 06:01 test8.txt -rw-r--r--. 1 root root 81 May 16 06:01 test9.txt [rootnode1 dir1]# tar -cvf file.tar test* --ignore-case --excludeTest7.txt # 忽略大小写匹配 test5.txt test6.txt test8.txt test9.txt [rootnode1 dir1]# tar -cvf file.tar test* --no-ignore-case --excludeTest7.txt # 严格大小写匹配 test5.txt test6.txt test7.txt test8.txt test9.txt [rootnode1 dir1]# tar -cvf file.tar test* --wildcards --excludetest7.* # 通配符匹配 test5.txt test6.txt test8.txt test9.txt [rootnode1 dir1]# tar -cvf file.tar test* --no-wildcards --excludetest7.* # 逐字符匹配 test5.txt test6.txt test7.txt test8.txt test9.txt [rootnode1 dir1]# 4.12.2.显示进度 [rootnode1 Desktop]# tar -zxvf dir1.2.tar.gz -C dir2/ --checkpoint10000 # 指定显示进度的频率值越大越不频繁 dir1/ dir1/file1.txt tar: Read checkpoint 10000 tar: Read checkpoint 20000 dir1/file2.txt tar: Read checkpoint 30000 tar: Read checkpoint 40000 ... ... [rootnode1 Desktop]# tar -zxvf dir1.2.tar.gz -C dir2/ --checkpoint10000 --checkpoint-actionecho%u files processed # 自定义进度显示 dir1/ dir1/file1.txt tar: 10000 files processed tar: 20000 files processed dir1/file2.txt tar: 30000 files processed tar: 40000 files processed ... ... [rootnode1 Desktop]# tar -zxvf dir1.2.tar.gz -C dir2/ --checkpoint10000 --checkpoint-actionttyout%s %u \r # 末尾可\r \n \t ... ... [rootnode1 Desktop]# 4.12.3.如果链接归档错误会输出信息 [rootnode1 dir1]# ln test5.txt test.txt [rootnode1 dir1]# tar -cvlf test.tar * test5.txt test6.txt test7.txt test8.txt test9.txt test.txt [rootnode1 dir1]# tar -tvf test.tar -rw-r--r-- root/root 28 2025-05-15 20:02 test5.txt -rw-r--r-- root/root 20 2025-05-15 20:02 test6.txt -rw-r--r-- root/root 2390 2025-05-15 20:02 test7.txt -rw-r--r-- root/root 25 2025-05-16 06:01 test8.txt -rw-r--r-- root/root 81 2025-05-16 06:01 test9.txt hrw-r--r-- root/root 0 2025-05-15 20:02 test.txt link to test5.txt [rootnode1 dir1]# 4.12.4.查看替换文件名称 [rootnode1 dir1]# tar -tf test.tar --transforms/test/aaa/g test5.txt test6.txt test7.txt test8.txt test9.txt test.txt [rootnode1 dir1]# tar -tf test.tar --transforms/test/aaa/g --show-transformed-names aaa5.txt aaa6.txt aaa7.txt aaa8.txt aaa9.txt aaa.txt [rootnode1 dir1]# cd /opt [rootnode1 opt]# tar -tf file.tar --strip-components2 root/Desktop/dir1/ root/Desktop/dir1/test5.txt root/Desktop/dir1/test6.txt root/Desktop/dir1/test7.txt root/Desktop/dir1/test8.txt root/Desktop/dir1/test9.txt root/Desktop/dir1/file.tar [rootnode1 opt]# tar -tf file.tar --strip-components2 --show-transformed-names dir1 dir1/test5.txt dir1/test6.txt dir1/test7.txt dir1/test8.txt dir1/test9.txt dir1/file.tar [rootnode1 opt]#
http://www.zqtcl.cn/news/160695/

相关文章:

  • 自媒体网站 程序18款免费软件app下载推荐
  • 产业园门户网站建设方案瑞昌网络推广
  • 长春市网站建设动漫wordpress主题下载地址
  • 如何做专业的模板下载网站wordpress 多网址
  • 做qq头像的网站wordpress 安装 服务器 系统
  • 怎样查网站的注册地点百度小说排行榜2021
  • 网站建设中中文模板wordpress siren
  • 设计本官方网站电脑版附近室内装修公司电话
  • 服务外包网站wordpress 禁止转载
  • l礼品文化网站建设不常见的网络营销方式
  • 做网站侵权腾讯企点打不开
  • iis 网站拒绝显示此网页上海网站建设类岗位
  • 营销型网站建设推荐google关键词
  • 网站上线是前端还是后端来做如何做垂直门户网站
  • 网站建设与管理2018海尔集团网站 建设目的
  • ps做网站大小wordpress调用 php文件
  • php网站忘记后台密码江苏网页制作报价
  • 网站模板 哪个好完备的常州网站推广
  • 衡水淘宝的网站建设濮阳市城乡一体化示范区主任
  • 公司网上注册在哪个网站商洛市商南县城乡建设局网站
  • 怎么才能让网站图文展示大连网站建设设计
  • 俱乐部网站 模板seo产品是什么意思
  • 新手学做网站的教学书建造师查询官网
  • win2012 iis添加网站群辉做网站服务器
  • 网站优化课程培训山东网站备案公司
  • top wang域名做网站好事业单位门户网站建设评价
  • 有什么网站可以做简历网站备案表格
  • 网站开发用什么图片格式最好厦门人才网个人会员
  • 关于网站开发的文献深圳网络推广代运营
  • 网站做app的重要性做静态网站有什么用