43

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?

gronostaj
  • 55,965
  • 20
  • 120
  • 179
simon
  • 1,614
  • 3
  • 17
  • 24

1 Answers1

68

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)

Cristian Ciupitu
  • 5,513
  • 2
  • 37
  • 47
Doug Harris
  • 27,333
  • 17
  • 78
  • 105