How to set max line in cat command

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.


Use head -n $NUMBER_OF_LINES instead of cat.

And watch out for useless uses of cat.