Computer Science - Unix - Discussion

Discussion Forum : Unix - Section 1 (Q.No. 3)
3.
Which command is used to display the top of the file?
cat
head
more
grep
None of the above
Answer: Option
Explanation:
The head command displays the first few lines at the top of a file. It can be useful when you want a quick peek at a large file, as an alternative to opening the file.
Discussion:
3 comments Page 1 of 1.

Kamal verma said:   8 years ago
The Head command display top 10 lines from the file.

$ head file.text
It will display top 10 lines of file.text.
Its opposite is tail command is display below 10 line of file.
$tail file.text
Options are used with this as line count.
$head -3 file.txt
Display to three line of file.

Arnab Pathak said:   1 decade ago
Actually if head is used without any numbers by default it shows exactly top 10 lines of a file.

Sandeep said:   1 decade ago
Even we can use cat (along with head) to display top of the file.
E.g. cat filename | head -1

Or this is achieved with "sed" command (which is powerful text editor).
E.g. sed -n '1p' filename
sed '1q' filename

Post your comments here:

Your comments will be displayed after verification.