Unix / Linux: Show First 10 or 20 Lines Of a File

In Linux/Unix, you can use the “head” command to display the first N lines of a file. By default, the head command displays the first 10 lines of a file. To display a different number of lines, use the “-n” option followed by the number of lines you want to see.

For example, to display the first 20 lines of a file named “file.txt”, use the following command:

$ head -n 20 file.txt

You can also use the “less” command to view the contents of a file one page at a time, and navigate through the file using the up and down arrow keys. To display the first 20 lines of a file using the “less” command, use the following command:

$ less -N file.txt

Leave a Comment