Head -n, –lines=[-]NUM option prints the first NUM lines instead of the first 10; with the leading ‘-‘, print all but the last NUM lines of each file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
## create a file with 100 lines > myfile; i=1; while [ $i -le 100 ]; \ do echo "$i" >> myfile; ((i++)); done ## create some additional files cp myfile myfile1 cp myfile myfile2 ## default head myfile ## by default, returns top 10 lines ## NUM = positive integer head -n 20 myfile ## returns top 20 lines ## NUM = negative integer head -n -100 myfile ## returns all lines except last 100 lines rm myfile |