Create a tar.xz in one command

前端 未结 5 2025
逝去的感伤
逝去的感伤 2021-01-29 18:32

I am trying to create a .tar.xz compressed archive in one command. What is the specific syntax for that?

I have tried tar cf - file | xz file.tar.xz

5条回答
  •  遇见更好的自我
    2021-01-29 19:12

    If you like the pipe mode, this is the most clean solution:

    tar c some-dir | xz > some-dir.tar.xz
    

    It's not necessary to put the f option in order to deal with files and then to use - to specify that the file is the standard input. It's also not necessary to specify the -z option for xz, because it's default.

    It works with gzip and bzip2 too:

    tar c some-dir | gzip > some-dir.tar.gz
    

    or

    tar c some-dir | bzip2 > some-dir.tar.bz2
    

    Decompressing is also quite straightforward:

    xzcat tarball.tar.xz | tar x
    bzcat tarball.tar.bz2 | tar x
    zcat tarball.tar.gz | tar x
    

    If you have only tar archive, you can use cat:

    cat archive.tar | tar x
    

    If you need to list the files only, use tar t.

提交回复
热议问题