cat file | … vs … <file

前端 未结 7 2025
北荒
北荒 2020-12-16 13:59

Is there a case of ... or context where cat file | ... behaves differently than ... ?

7条回答
  •  情歌与酒
    2020-12-16 14:08

    When reading from a regular file, cat is in charge of reading the data, performs it as it pleases, and might constrain it in the way it writes it to the pipeline. Obviously, the contents themselves are preserved, but anything else could be tainted. For example: block size and data arrival timing. Additionally, the pipe in itself isn't always neutral: it serves as an additional buffer between the input and ....

    Quick and easy way to make the block size issue apparent:

    $ cat large-file | pv >/dev/null
    5,44GB 0:00:14 [ 393MB/s] [              <=>                                  ]
    $ pv /dev/null
    5,44GB 0:00:03 [1,72GB/s] [=================================>] 100%
    

提交回复
热议问题