I want to tar the output of a command, say cat hello.world
, to a compressed tar file.
I don’t want to save a temporary file and later tar it manually.
How can I do this?
tar
files store not just the contents of files but also the file names, the file permissions, and more. None of that applies to "the output of a command."
From your description, it sounds like you just need gzip
. For example:
command | gzip >output.gz
This captures the output of command
, compresses it, and saves it to file output.gz
.
tar
is a tool to join multiple files into one, the compression options are just a convenience to use it together with gzip
and the like.
tar
pretty much requires real files, in order to give meaningful names in the archive. Your best bet is probably to use the tarfile module of Python.