Recently saw article on one LinedIn channel explaining Linux shell pipes and again saw the same mistake - 99% engineers doesn’t know how pipes actually works!
Absolutely sure you will be “not absolutely sure” how long that command sleep:
sleep 5 | sleep 5 | sleep 5 | sleep 5
You may “suspect” that it will be 20 seconds, but it’s not true.
It’s surprising people, that ALL commands in pipe running simultaneously! And command will sleep 5 secs.
You can check it with “ps -ef | grep slee[p]” while sleep is running.
That’s the reason why you see intermediate result when grepping large file and not waiting for command to finish, in case of sequential run of commands in pipe.
Send this riddle to your colleagues, and Happy Friday!
Comments