tar to pipe but keep -v verbose output separate from STDERR

If your system supports /dev/fd/n:

tar cvf /dev/fd/3 ./foo 3>&1 > foo.out 2>foo.err | squish > foo.tar.S

Which with AT&T implementations of ksh (or bash or zsh) you could write using process substitution:

tar cvf >(squish > foo.tar.S) ./foo > foo.out 2>foo.err

That's doing exactly the same thing except that this time, the shell decides of which file descriptor to use instead of 3 (typically above 9). Another difference is that this time, you get the exit status of tar instead of squish. On systems that do not support /dev/fd/n, some shells may resort to named pipes for that feature.

If your system doesn't support /dev/fd/n or your shell can't make use of named pipes for its process substitution, that's where you'd have to deal with named pipes by hand.


You have to use a named pipe for that.

First create one in the folder:

mkfifo foo.pipe

Then use that command:

tar cvf foo.pipe ./foo >foo.out 2>foo.err & cat foo.pipe >foo.tar

Notice: the cat-part, can now also be gzip or whatever, that can read from a pipe:

tar cvf foo.pipe ./foo >foo.out 2>foo.err & gzip -c foo.pipe >foo.tar

Explanation:

The output is written to the name pipe (foo.pipe), where another proccess (cat, gzip, netcat) reads from. So you don't loose the stdout/stderr channels for information.


GNU tar's --index-file option works well:

tar cvf - ./foo 2>foo.err --index-file=foo.out | squish > foo.tar.S

Tags:

Io

Ksh

Tar