Bash – Pipe a command to pv but hide all the original command’s output

bashpipepv

I'm trying to use pv, but I want to hide the command I piped in's output while still be able to see pv's output. Using command &> /dev/null | pv doesn't work (as in, pv doesn't receive any data). command produces output on both standard output and standard error, and I don't want to see either.

I tried using a grep pipe (command &> /dev/null | pv | grep <=>) but that now and then outputs things to the terminal.

Best Answer

man pv says:

To use it, insert it in a pipeline between two processes, with the appropriate options. Its standard input will be passed through to its standard output and progress will be shown on standard error.

The output you see comes from pv. The progress bar is on stderr, and the content you piped in is on stdout. You can redirect the output:

cmd | pv > /dev/null

and you will still get the progress bar output.

If the command produces its own text on stderr as well, you can redirect that explicitly to /dev/null, before passing on the output to pv:

cmd 2>/dev/null | pv > /dev/null
Related Question