cat a file having size of say 10 GB, and I pipe that to
cat work if my system only has 2 GB of RAM and 1 GB of swap space? I want to know the internal details.
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.