4

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.

1
  • 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. Commented Jan 21, 2017 at 17:04

1 Answer 1

8

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.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.