3 ms·
If we cat this file, it will be printed to the terminal. > cat brothers_karamazov.txt ... many lines of text! ***FINIS*** It takes a noticeable
by cperciva 7y ago
If we cat this file, it will be printed to the terminal.
> cat brothers_karamazov.txt
... many lines of text!
***FINIS***
It takes a noticeable amount of time to finish.
The amount of time it takes for cat(1) to read and output the file is almost certainly insignificant. The time the author is noticing is probably related to how long it takes for his console to process the text.
- kccqzy 7y agoAgreed. This can be easily verified by putting `time` in front of the cat to measure the time taken. Even for huge text files, the wall clock time might be significant but the "user" time is likely still zero.
- wolf550e 7y agoor redirect cat to /dev/null and see how fast that is
- happytoexplain 7y agoThis is the first thing I noticed too. >how does cat know to stop when head is finished I'm no expert on Unix, so correct me if I'm wrong, but surely this line of reasoning is misleading because pipes create a unidirectional data flow, so `cat` can not know anything about `head`. It does not "stop" - it passes the whole text along just as it did without the pipe. As you said, the delay comes in printing to the console, not in the `cat` command.
- cperciva 7y agoPipes aren't completely unidirectional. You get one bit of information flowing back: Whether the read end of the pipe is still open.
- kyuudou 7y agoThis is a great example of Useless Use of cat and why it is bad - the full text is indeed sent through the pipe simply for head to chop n initial lines. I've actually had "developers" go "but, readability". Yea ok.