Display the first few lines of a file
You use the head
command to do this, with the -n argument with the number of lines from each file, like this:
head -n3 *
or
head -n3 *.txt
This also works for a single file:
head -n3 filename.txt
head
You use head
with the -n
option.
head -n 10 FILE
This will print the first ten lines of a file.
Another useful variation would be -n -NUMBER
.
head -n -10 FILE
This will print all but the last ten lines of a file.
To solve your problem and get your desired output you can do the following.
basename * && head -n NUMBER *
or
basename *.FILETYPE && head -n NUMBER *.FILETYPE
This will get you following output:
FILENAME
LINE ONE
LINE TWO
LINE THREE
This will do what you want, hopefuly:
find . -print -exec head {} -n 3 \;
-print
will show the filename and the rest (from -exec
) will show the first 3 lines of each file
Change the number according to your needs...