Linux归档工具---tar

      

  tar指令用法:tar [-][options] [pathname...]

    主要的操作模式:

      -A, --catenate, --concatenate

      

      -c,--create:创建归档

      -d,diff,compare:比较归档文件与操作系统的区别

      --delete:从归档中删除(注意,此处的--并不是普通的描述标记,与-c,-d这种同级)

      -r,--append:递归操作

      -t,--list:列表,列出归档中的文件(不展开归档文件直接查看)

      --test-table:测试卷标存档并退出

      -u,--update:只是将新的文件添加复制到归档文件

      -x, --extract, --get:展开归档

    其他操作选项:

      -[0-7]:不同的归档压缩率(压缩后的文件越小就越节省硬盘空间,不过意味着压缩过程中消耗的时间越长)

      -a, --auto-compress:使用归档文件后缀名来确定压缩算法

--add-file=FILE:将FILE添加到归档文件中(如果它的名字以--开头就非常有用了)

      --anchored:文件名起始模式匹配

      --no-anchored:默认从"/"开始匹配

      --atime-preserve:保存文件访问时间

      --no-auto-compress:不使用文件后缀名确定压缩算法

      -b, --blocking-factor:指定块状 BLOCKS X 512

      -B, --read-full-records:重新以我们读的方式指定block

      -- backup:删除前备份,用于版本选择

      -C,--directory DIR:更改存储路径

      --check-device:在创建归档时检查设备数量(默认)

      --no-check-device:默认不检查数量

      --checkpoint:每NUMBER个文件归档时显示进程归档信息(默认为10)

      --checkpoint-action=ACTION:在每xx时添加ACTION

      --delay-directory-restore:提取的延迟设置修改时间和权限

      --no-delay-directory-restore:删除--delay-directory-restore的设置

      --exclude=PATTERN:通过给定的通配符排除文件

      --exclude-backups:排除更新文件和锁的文件

      --exclude-caches:排除包含CACHEDIR.TAG的内容

      --exclude-caches-all:排除所有包含CACHEDIR.TAG的文件夹

      --exclude-caches-under:排除包含有CACHEDIR.TAG文件夹下的所有内容

      --exclude-tag=FILE:排除符合条件的文件夹

      --exclude-tag-all=FILE:排除符合条件文件夹下的所有内容

      --exclude-tag-under=FILE:

      --exclude-vcs:排除系统版本控制

      -f, --file ARCHIVE:将归档文件存到ARCHIVE

      -F, --info-script, --new-volume-script NAME:在归档结束后执行指定脚本

      --force-local:

      --full-time:打印文件详细时间

      -g, --listed-incremental FILE:处理符合GUN-format的增量备份

      -G, --incremental:处理符合GUN-format的备份文件

      --group=NAME:将归档文件指定属主

      -h, --dereference:遵循符号链接,他们指出,归档和转储文件

       -H, --format FORMAT:

        如果符合下列条件即创建归档文件:

          --format=gun

            GUN tar 1.13.x format    

          --format=oldgnu
            GNU format as per tar <= 1.12

          --format=pax

            POSIX 1003.1-2001 (pax) format

          --format=posix

            same as pax

          --format=ustar
            POSIX 1003.1-1988 (ustar) format

          --format=v7
            old V7 tar format

      --hard-dereference

        遵循硬链接;存档并转储文件参考

      -i, --ignore-zeros

        忽略0的块

      -I, --use-compress-program PROG

        过滤PROG,必须与-d同时使用

      --ignore-case

        忽略case

      --no-ignore-case

        敏感模式匹配(默认)

      --ignore-command-error

        忽略异常退出

      --no-ignore-command-error

        捕获非0的退出码

      --ignore-failed-read

        在遇到没有读权限的文件时不退出

      --index-file=FILE

        给文件一个版本标记

      -j, --bzip2

      -J, --xz

      -k, --keep-old-files

        don‘t replace existing files when extracting

      -K, --starting-file MEMBER-NAME

        begin at member MEMBER-NAME in the archive

      --keep-newer-files

        don‘t replace existing files that are newer than their archive copies

      -l, --check-links

        print a message if not all links are dumped

      -L, --tape-length NUMBER

        change tape after writing NUMBER x 1024 bytes

      --level=NUMBER
        dump level for created listed-incremental archive

      --lzip

      --lzma

      --lzop

      -m, --touch

        don‘t extract file modified time

      -M, --multi-volume

        create/list/extract multi-volume archive

      --mode=CHANGES

        force (symbolic) mode CHANGES for added files

      --mtime=DATE-OR-FILE
        set mtime for added files from DATE-OR-FILE

      -n, --seek

        archive is seekable

      -N, --newer, --after-date DATE-OR-FILE

        only store files newer than DATE-OR-FILE

      --newer-mtime=DATE

        compare date and time when data changed only

      --null
        -T reads null-terminated names, disable -C

      --no-null

        disable the effect of the previous --null option

      --numeric-owner

        always use numbers for user/group names

      -O, --to-stdout

        extract files to standard output

      --occurrence

        process only the NUMBERth occurrence of each file in the archive;

      --old-archive, --portability

        same as --format=v7

      --one-file-system

        stay in local file system when creating archive

      --overwrite
        overwrite existing files when extracting

      --overwrite-dir
        overwrite metadata of existing directories when extracting (default)

      --no-overwrite-dir
        preserve metadata of existing directories

      --owner=NAME
        force NAME as owner for added files

      -p, --preserve-permissions, --same-permissions
        extract information about file permissions (default for superuser)

      -P, --absolute-names
        don‘t strip leading `/‘s from file names

      --pax-option=keyword[[:]=value][,keyword[[:]=value]]...

        control pax keywords

      --posix
        same as --format=posix

      --preserve
        same as both -p and -s

      --quote-chars=STRING
        additionally quote characters from STRING

      --no-quote-chars=STRING
        disable quoting for characters from STRING

      --quoting-style=STYLE

        set name quoting style; see below for valid STYLE values

      -R, --block-number
        show block number within archive with each message

      --record-size=NUMBER
        NUMBER of bytes per record, multiple of 512

      --recursion
        recurse into directories (default)

      --no-recursion
        avoid descending automatically in directories

      --recursive-unlink
        empty hierarchies prior to extracting directory

      --remove-files
        remove files after adding them to the archive

      --restrict
        disable use of some potentially harmful options

      --rmt-command=COMMAND
        use given rmt COMMAND instead of rmt

      --rsh-command=COMMAND
        use remote COMMAND instead of rsh

      -s, --preserve-order, --same-order
        sort names to extract to match archive

      -S, --sparse
        handle sparse files efficiently

      --same-owner
        try extracting files with the same ownership as exists in the archive (default for superuser)

      --no-same-owner
        extract files as yourself (default for ordinary users)

      --no-same-permissions
        apply the user‘s umask when extracting permissions from the archive (default for ordinary users)

      --no-seek
        archive is not seekable

      --show-defaults
        show tar defaults

      --show-omitted-dirs
        when listing or extracting, list each directory that does not match search criteria

      --show-transformed-names, --show-stored-names
        show file or archive names after transformation

      --sparse-version=MAJOR[.MINOR]
        set version of the sparse format to use (implies --sparse)

      --strip-components=NUMBER
        strip NUMBER leading components from file names on extraction

      --suffix=STRING
        backup before removal, override usual suffix (‘~‘ unless overridden by environment variable SIMPLE_BACKUP_SUFFIX)

      -T, --files-from FILE
        get names to extract or create from FILE

      --to-command=COMMAND
        pipe extracted files to another program

      --totals
        print total bytes after processing the archive;

      --transform, --xform EXPRESSION
        use sed replace EXPRESSION to transform file names

      -U, --unlink-first
        remove each file prior to extracting over it

      --unquote
        unquote filenames read with -T (default)

      --no-unquote

        do not unquote filenames read with -T

      --utc
        print file modification times in UTC

      -v, --verbose
        verbosely list files processed

      -V, --label TEXT
        create archive with volume name TEXT; at list/extract time, use TEXT as a globbing pattern for volume name

      --volno-file=FILE
        use/update the volume number in FILE

      -w, --interactive, --confirmation

      -W, --verify
        attempt to verify the archive after writing it

      --warning=KEYWORD
        warning control

      --wildcards
        use wildcards (default for exclusion)

      --wildcards-match-slash
        wildcards match `/‘ (default for exclusion)

      --no-wildcards-match-slash
        wildcards do not match `/‘

      --no-wildcards
        verbatim string matching

      -X, --exclude-from FILE
        exclude patterns listed in FILE

      -z, --gzip, --gunzip --ungzip

        -Z, --compress, --uncompress

  关于运行环境:tar的行为是依赖运行环境的,比如以下这些环境的配置

      

      SIMPLE_BACKUP_SUFFIX
        Backup prefix to use when extracting, if --suffix is not specified. The backup suffix defaults to `~‘ if neither is
        specified.

      TAR_OPTIONS
        Options to prepend to those specified on the command line, separated by whitespace. Embedded backslashes may be used
        to escape whitespace or backslashes within an option.

      TAPE Device or file to use for the archive if --file is not specified. If this environment variable is unset, use stdin or
      stdout instead.

      TAR_LONGLINK_100

tar功能十分强大,了解这些功能以后可以方便我们使用,一般常用

-c:创建归档
-x:展开归档
-t:不展开而直接查看被归档的文件
-z:使用gzip压缩
-j:使用bz2压缩
-J:使用xz压缩

  使用的小例子:

      tar -czf script.tar.gz script

      tar -xf script.tar.gz

 

时间: 2024-07-30 06:25:49

Linux归档工具---tar的相关文章

Linux基础之压缩与归档工具

压缩出现的原因简析 压缩为什么会诞生?我们可以想象一下如果没有压缩的场景:一个游戏10G,下载下来得一整天,我们要上传一个1G电影得1天,磁盘不够用了,再买一块扩展...上传下载好耗费时间啊,买一块硬盘好贵.如果我们可以将游戏压缩到原来的80%,我们就可以节省下来20%的时间,同时也节省了一部分磁盘空间.所以压缩诞生的目的首先是解决磁盘空间问题,其次也是为了节省我们上传下载的时耗问题. 看起来它的出现真的是好的无以复加,不过它也有它的不足,压缩必定伴随着压缩这个过程,同样若是想要解压也需要解压这

谢烟客---------Linux之压缩解压缩及归档工具的使用

压缩工具 compress/uncompress:  .Z结尾 gzip/gunzip: .gz结尾 bzip2/bunzip2: .bz2结尾 xz/unxz: .xz后缀 压缩及归档工具: zip/unzip 归档工具: tar,cpio(特殊场景) gzip/gunzip/zcat命令 1.LZ77压缩算法 2.压缩比不高:快速.高效 3.压缩/解压缩后删除原文件,为了节约空间 4.纯文本压缩,二进制压缩意义不大 5.压缩目录,-r gzip [OPTIONS...] FILE     -

linux文件压缩与归档工具

1.compress/uncompress  .Z 格式 compress [-dfvcVr] [-b maxbits] [file -] -d: 解压缩,相当于 -c: 结果输出至标准输出,不删除原文件 compress -c  file > file.Z -v: 显示详情 uncompress 解压缩 -c -d file.Z > file   ->  解压,但是保持源文件 zcat file.Z >file 2. gzip/gunzip     .gz 格式 gzip [OP

Linux命令(30):tar命令-归档工具

tar命令 功能说明 tar是tape archive的缩写,是Linux下经常使用的归档工具,经常看到文件名以.tar和tgz结尾的文件,它们分别是用普通的tar命令归档的文件和用gzip归档的文件.tar归档文件可以由许多独立的文件.一个或多个目录层次或者两者的混合组合而成.用法如下:   tar [主选项+辅助选项] 文件或目录 常用参数 选项 说明 -c 新建文件 -r 列出归档文件的内容 -t 列出档案文件中已经归档的文件列表 -x 从打包的档案文件中还原文件 -u 更新档案文件,用新

Linux压缩归档工具

压缩工具: 1> zip,unzip 格式:  #zip 压缩文件名 原文件名 1.递归的压缩一个目录及目录下的文件: #zip -r var-log-dir  /var/log 2.压缩目录下的多个文件: #zip var-log-files  /var/log/*此方法不会递归压缩子目录下的文件. 3.查看解压缩过程中的详细信息: #unzip -v  压缩文件 4.在不解压的情况下查看压缩文件里的文件列表: #unzip -l 压缩文件 5.检查压缩文件的完整性: #unzip -t 压缩

linux之压缩解压缩及归档工具

压缩.解压缩及归档工具 1.压缩文件:XXXXXzip    filename 2.解压文件 Xunzip   filename.Xzip 3.查看压缩文件: Xcat   filename.Xzip 4.关于压缩工具 工具 文件扩展名 描述 Bzip2 .bz2 使用Burrows-Wheeler块排序文本压缩算法和Huffman编码 Compress .z 原Unix文件压缩工具,现在以你个很少使用 Gzip .gz Gun项目的压缩工具:使用Lempel-Ziv编码 Zip .zip Un

linux压缩、解压缩及归档工具

压缩.解压缩及归档工具 compress/uncompress: .Z    gzip/gunzip: .gz    bzip2/bunzip2: .bz2    xz/unxz: .xz    zip/unzip    tar, cpio 1.gzip/gunzip gzip [OPTION]... FILE ...            -d: 解压缩,相当于gunzip            -c: 将结果输出至标准输出:            -#:1-9,指定压缩比: zcat:不显式

Linux压缩及归档工具整理

gzip:.gz,只能压缩文件,不能压缩目录 gzip somefiles:压缩完成后会删除原文件 -d:解压缩 -# :1-9,指定压缩比,默认为6 gunzip:解压缩 gunzip somefiles.gz:解压完成后删除原压缩文件 zcat somefiles.gz:查看gzip压缩文件内的文本文件内容 bzip2:.bz2,只能压缩文件,不能压缩目录 比gzip有着更大压缩比的压缩工具: bzip2 somefiles:压缩完成后会删除原文件 -d:解压 -# :1-9,指定压缩比,默

Linux归档和压缩

归档操作实际上相当于"打包",即将多个文件和目录合并为一个整体文件,以方便传递或携带. 而压缩操作可以进一步降低打包好的归档文件所占用的磁盘空间,充分提高备份介质的利用率. Linux系统中最常用的压缩命令工具包括gzip.bzip2,最常用的归档命令工具为tar.使用命令可以通过特定选项自动调用gzip或bzip2,以完成归档压缩整套流程,当然也可以完成解压.释放已归档文件的整套流程. 使用gzip制作的压缩文件默认的扩展名为".gz".制作压缩文件时,使用&qu