Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I'm looking for a bash command, which I can use to limit the number of lines of a file or another command output. E.g.

ls -thor | limit 10

would limit the output of the ls command to 10 lines (in the example, the command "limit" is naturally a imaginary command, whose equivalent I'm looking for). Is there such command, or a related solution?

share|improve this question
up vote 23 down vote accepted

Use head:

ls -l | head -n 15

10 lines is the default. Read the head man page for more options.

(older versions of head also support usage without the explicit -n as in head -15)

share|improve this answer
beat me to it :) – warren Sep 11 '09 at 11:18
Thx. I should have figured it out, it's obvious when you know that there is a "tail" command.. :) – simon Sep 11 '09 at 11:29
Syntax -integer is (at least in GNU version of head/tail discouraged - you should be using -n 15) – user7385 Sep 11 '09 at 11:51
I didn't know that. Old habits die hard. I'll have to try to learn that. – Doug Harris Sep 11 '09 at 13:49
The current GNU Coreutils version head accepts head -15 (but only if it's the first argument). The document describes this option as obsolete. – Keith Thompson Jan 15 '12 at 16:20

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.