I want to use the "--totals" option in GNU tar for some reporting, however I have discovered that it writes the output to stderr not stdout and I would like to know why. This is running from BASH.
mkdir /tmp/test
touch /tmp/test/foo.file
cd /tmp/
tar --totals -clpzf test.tar.gz test 2> /tmp/tar.stderr 1> /tmp/tar.stdout
the tar command runs without error.
echo $?
0
The output of "--totals" ends up in stderr.
$ cat /tmp/tar.stderr
Total bytes written: 10240 (10KiB, 3.8MiB/s)
Simply because you can tell tar to use stdout as a target file, for example when piping to a compression program it doesn't yet know about. If, for instance, tar didn't know about bzip2, you'd still be able to use it as tar -cf - * | bzip2 -9c > file.tar.bz2 . The added statistics would, in this example, be compressed instead of shown. The only way around this: report to stderr instead of stdout.