To display the first line of a file in Unix or Linux, you can use the head
command with the -n 1
option.
Here is the basic syntax for using the head
command:
head [-n lines] [file ...]
The -n
option specifies the number of lines to display, and the lines
argument is the number of lines to display. The file
argument is the name of the file to display.
For example, to display the first line of the file file.txt
, you can use the following command:
head -n 1 file.txt
This will display the first line of file.txt
.
You can also use the head
command without the -n
option to display the first 10 lines of the file by default.
For example:
head file.txt
This will display the first 10 lines of file.txt
.
Alternatively, you can use the sed
command to display the first line of a file. The sed
command is a stream editor that can be used to perform various text transformations on an input stream.
To display the first line of a file with sed
, you can use the following command:
sed -n '1p' file.txt
This will display the first line of file.txt
. The -n
option tells sed
to suppress automatic printing of pattern space, and the 1p
command tells sed
to print the first line (1
)