$ cat "

Quick Tip: Listing the First/Last N Lines of a File under Linux

"

As for everything else, there are of course commands for displaying the first/last N lines of a text file in Linux. These commands are called head and tail.

Tail is super useful when you are dealing with long log files, and you're just interested in what's happened recently.

To get the first/last 25 lines of a given file you can execute the following commands:



head -25 my_file.txt
tail -25 my_file.txt

or you can pipe stuff to them:



cat my_file.txt | head -25
cat my_file.txt | tail -25

Written by Erik Öjebo 2012-11-24 22:53

    Comments