Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi while I am playing with Ubuntu head command of CLI, I came to a situation.There what ever I am giving as input thats echoing automatically.

The command and its play mentioned in the image.

so could somebody explain me whats happening in there ? enter image description here.

Note: here h.txt is a general text file I made with raw information.

share|improve this question
I'm not entirely sure what the problem is. You mean that after you type too much, head does not stop echoing (i.e. it behaves like cat)? That would be a very odd bug, maybe try with head -n1 -. – Andrea Corbellini Feb 2 '13 at 13:48
Ah, sorry, I have completely misunderstood the question. – Andrea Corbellini Feb 2 '13 at 13:51
@AndreaCorbellini Its ok amigo.try what I have done and you will get it. I am sure. – Raja Feb 2 '13 at 13:52
up vote 3 down vote accepted

With the - option you're reading from "standard input". From the manpage of head(1):

when FILE is -, read standard input.

Your keyboard is the standard input in this case, as your shell doesn't provide another to head here. Everytime you provide a line, it will just process it up to 10 times as it's outputting the first 10 lines by default. As your shell will also print the input you provide, you'll see all lines twice.

When you are providing a stream to the standard input to head, then your keyboard input will not be grabbed. E.g.:

echo blaat | head -

will make echo output "blaat" to standard output and your shell will connect that to standard input of head (as expressed by the |).

Note: Without any arguments given head will also read from standard input.

A more useful (random) example for the use in connecting up standard input with head is this:

grep error /var/log/syslog | grep -iv apache | head

Will print the first 10 lines matching error, but not apache from /var/log/syslog.

share|improve this answer
is there any use ? I mean where we can use this ? – Raja Feb 2 '13 at 14:00
@snow What exactly are you referring to? The use in head or standard input via keyboard in general? I think the first has been explained in my answer and the the latter is being used very widely in the terminal (entering sudo password for example), just not very common in combination with head. – gertvdijk Feb 2 '13 at 14:02
last words are interesting , could you add a bit more about relation of head & password . – Raja Feb 2 '13 at 14:04
@snow What? No, passwords and head have very few in combination to explain about. I think you're making the wrong connections about my points. There's no relation except that passwords are being read by standard input and that head can also read from standard input. Like 99% of the command line tools. – gertvdijk Feb 2 '13 at 14:08
done , Thanks for your valuable time. – Raja Feb 2 '13 at 14:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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