0

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?

1
  • 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. May 10, 2016 at 17:01

1 Answer 1

1

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.

1
  • 1
    +1 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.
    – l0b0
    May 8, 2016 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .