0

I was watching this command run

tar cf - 20180412 -P | pv -s $(du -sb 20180412 | awk '{print $1}') | gzip > 20180412.tar.gz
9.02GiB 0:01:20 [ 114MiB/s] [===================================================================================================================================================================>] 100%

and wondered how can pv work. I thought pipes were eager, but I think this pv can only work right if the pipes are lazy.

So, are bash pipes lazy or eager?

jperelli
  • 223
  • 5
  • 10

1 Answers1

6

Pipe behavior doesn't matter for the purpose of this command at all.

Although tar can start first, it usually feeds the pipe starting from the time zero so it will very soon block on a pipe and wait for pv to start consumption. In turn, pv doesn't even start before commands inside $( ) start and finish.

Practically it doesn't matter if pv starts as soon as possible or waits for the first byte to appear on pipe (the answer is: as soon as possible, by the way).

What you might miss is that du estimates the input directory (not the tarfile) and at the same time tar reads the same input directory on its own.

kubanczyk
  • 13,502
  • 5
  • 40
  • 55