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>
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.