Which command is used to display the first few lines of a file in UNIX?

Which command is used to display the first few lines of a file in UNIX?

a) head
b) tail
c) cat
d) more

Answer:

a) head

Explanation:

The head command in UNIX is used to display the first few lines of a file. By default, it shows the first 10 lines, but you can specify the number of lines you want to display by using the -n option. For example, head -n 5 filename will display the first 5 lines of the file.

It is particularly useful when you only want a quick preview of a file without opening it entirely. Combined with commands like tail or cat, head provides flexible control over file content display.

Understanding head is essential for working with large text files. Whether you need to preview log files, configuration files, or any large data file, head gives you a quick snapshot of the beginning of the file.

Reference:

Top 50 Unix MCQ Questions & Answers

Scroll to Top