What is the correct flag for the head command to show a specific number of lines?

Disable ads (and more) with a premium pass for a one time $4.99 payment

Boost your Linux skills with the CompTIA Linux+ Certification Exam simulator. Engage with multiple choice questions and detailed feedback. Master Linux concepts and prepare for your exam with confidence!

The flag to use with the head command to specify the number of lines to display is indeed -n. When using the head command, appending -n followed by a number allows users to define how many lines from the beginning of the file they wish to see.

For example, executing head -n 5 filename will show the first five lines of the specified file. This flexibility is particularly useful for quickly previewing parts of a larger file without having to open it fully.

The other options do not serve this purpose: -l is typically associated with listing directory contents in other commands, --lines is not a standard option for head, and -c is used to specify the number of bytes to display instead of lines. This distinction highlights how the commands' flags are tailored for specific functionalities, making -n the correct choice for setting the number of lines to output.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy