递归tar压缩?

Sam*_*Sam 45 command-line tar

我想创建一个 tar 文件来压缩包含子文件夹的文件夹。我正在终端中尝试使用以下命令 int:

tar -czf folder directorios.tar.gz
Run Code Online (Sandbox Code Playgroud)

directory.tar.gz 将是结果

and*_*.46 75

尝试:

tar -czvf directorios.tar.gz folder
Run Code Online (Sandbox Code Playgroud)

一些注意事项:

  1. 递归是默认的,来自tar手册页:

    -c, --create
        Create a new archive.  Arguments supply the names of the files to be archived.
        Directories  are  archived  recursively,  unless  the --no-recursion option is
        given.
    
    Run Code Online (Sandbox Code Playgroud)

    虽然这可以通过使用--no-recursion选项关闭...

  2. 您需要存档名称-f选项中,正确的顺序是:

    tar -c [-f ARCHIVE] [OPTIONS] [FILE...]
             ^^^^^^^^^^
    
    Run Code Online (Sandbox Code Playgroud)
  3. 对于更灵活的命令行(特别是如果您想使用除 gzip 和 tar 之外的其他压缩实用程序),您可以省略该-z选项并使用-a--auto-compress选项以允许 tar根据存档后缀自动决定使用哪个压缩器:

    -a, --auto-compress
        Use archive suffix to determine the compression program.
    
    Run Code Online (Sandbox Code Playgroud)

    公认的后缀(及其伴随的压缩应用程序)是:

    • .gz : gzip
    • .tgz : gzip
    • .taz : gzip
    • .z:压缩
    • .taZ : 压缩
    • .bz2 : bzip2
    • .tz2:bzip2
    • .tbz2 : bzip2
    • .tbz : bzip2
    • .lz : lzip
    • .lzma : lzma
    • .tlz : lzma
    • .lzo : lzop
    • .xz : xz
    • .zst : zstd
    • .tzst : zstd

焦油很酷:)

参考:

  • 8.1.1 创建和读取压缩档案有关使用带有 tar 的自动压缩选项的声音信息以及使用更手动和更灵活的选项实现相同目标的可能性...