Computer Science - Unix - Discussion

Discussion :: Unix - Section 1 (Q.No.3)

3. 

Which command is used to display the top of the file?

[A]. cat
[B]. head
[C]. more
[D]. grep
[E]. None of the above

Answer: Option B

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.

Sandeep said: (May 20, 2013)  
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

Arnab Pathak said: (Jan 15, 2015)  
Actually if head is used without any numbers by default it shows exactly top 10 lines of a file.

Kamal Verma said: (May 8, 2017)  
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.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.