You can use the head command to display the top N lines of a file or pipe in Linux.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
## 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 ## multiple files also supported head myfile myfile1 myfile2 ## returns top 10 lines of each ## files along with filename as header ## top N lines (-n head -n 20 myfile ## returns top 20 lines ## with pipe ps -ax | head ## also works with pipe rm myfile |