1

Suppose I cat a file having size of say 10 GB, and I pipe that to head, would cat work if my system only has 2 GB of RAM and 1 GB of swap space? I want to know the internal details.

  • The answer provided by Celada is really straight to the point and can hardly be better. If it doesn't clarify what you're really looking for, you'll need to formulate another question differently. – Julie Pelletier Jan 21 '17 at 17:04
5

cat doesn't need to remember any parts of the file that it has already sent along from its input to its output. In other words, it uses O(1) memory.

head also doesn't need to remember parts of the file it has already sent along, it only needs to count them. Furthermore, it doesn't even need to read the whole of its input; it can stop when it reaches the amount of lines requested on output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.