What is the difference? It is performed in the same?
tar -czf files/compressed/gzip/archive.tar.gz -C files/original . tar -c -C files/original . | gzip -1 > files/compressed/gzip/archive.tar.gz
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
In the former, the implementation of tar uses a gzip library to perform the compression itself. In the latter the output of tar gets piped into a separate executable that performs the compression. The former is probably slightly more efficient as it doesn't involve extra system calls to write/read the data to/from the pipe, but a human would likely not notice the difference.
Let's do some tests.
time sh -c 'tar -czf test.tar.gz ~/Downloads' tar: Removing leading `/' from member names ===== JOB sh -c 'tar -czf test.tar.gz ~/Downloads' 74% cpu 30.02s real 20.64s user 1.82s sys
tar pipe to
time sh -c 'tar -c ~/Downloads | gzip -1 > test.tar.gz' tar: Removing leading `/' from member names ===== JOB sh -c 'tar -c ~/Downloads | gzip -1 > test.tar.gz' 65% cpu 27.23s real 16.07s user 1.88s sys
It seems reasonable to me that the
tar pipe to
gzip can be faster because they were run in parallel in multiple core machine (mine has 2 CPUs).