20

in grep command I can set max line to output with parameter -m. How I can specify max line in cat command ?

2 Answers 2

28

cat is dedicated to whole files.

You are looking for either head or tail, depending if your counting starts from the beginning or end of a file.

Examples

  • head --lines=100 print the first 100 lines
  • head --lines=-100 print all but the last 100 lines
  • tail --lines=100 print the last 100 lines
  • tail --lines=-100 print all but the first 100 lines

Note

You may also have a look at tac. The result is clear, if you compare the word tac with cat.
tac prints out all lines in reverse ordering.

2
  • I want to println file from start. Thx head is what I looking for
    – hudi
    Mar 12, 2013 at 8:37
  • @hudi updated answer should make it clear.
    – user86064
    Mar 12, 2013 at 8:42
2

Use head -n $NUMBER_OF_LINES instead of cat.

And watch out for useless uses of cat.

1
  • @hudi: Read the answer again.
    – BatchyX
    Mar 12, 2013 at 8:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .