See What are the shell's control and redirection operators? and Order of redirections for background.
tar -czf - ./Downloads/ | (pv -p --timer --rate --bytes > backup.tgz)
tells the shell to run tar -czf - ./Downloads/
with standard output redirected to (pv -p --timer --rate --bytes > backup.tgz)
.
(pv -p --timer --rate --bytes > backup.tgz)
tells the shell to run pv -p --timer --rate --bytes
with standard input connected to the pipe from tar
, and standard output redirected to backup.tgz
. The overall effect, since tar
is told to create a compressed archive, outputting to its standard output (f -
), is to build a compressed archive, pipe it through pv
, and then have pv
write it to backup.tgz
. pv
displays a progress bar, updated as data flows through it.
The parentheses aren’t required.
You second command changes the second half of the first pipe:
(pv -n > backup.tgz) 2>&1
again writes to backup.tgz
, but also redirects the subshell’s (introduced by the parentheses) standard error to standard output, and feeds that into dialog
which produces its own progress display.
The parentheses are required here if the redirections are set up in the order given in your command: pv -n > backup.tgz 2>&1
would redirect both pv
’s standard output and standard error to backup.tgz
, which isn’t what you want. The desired effect can also be achieved by redirecting standard error first: pv -n 2>&1 > backup.tgz
.