Linux / Unix: Display First Line of a File

In Linux/Unix, you can use the “head” command to display the first line of a file. The head command by default displays the first 10 lines of a file. To display only the first line, use the “-n 1” option:

$ head -n 1 file.txt

Alternatively, you can use the “sed” command to display the first line of a file:

$ sed -n '1p' file.txt

You can also use the “cat” command along with the “awk” command to display the first line of a file:

$ cat file.txt | awk 'NR==1'

Leave a Comment