Forrest logo
back to the head tool

head:tldr:fa104

head: Output everything but the last few lines of a file.
$ head --lines -${count} ${filename}
try on your machine

The command "head --lines -${count} ${filename}" is used to display the first few lines of a file.

Here is a breakdown of the command components:

  • "head" is the command itself. It is used to retrieve the top portion of a file, by default displaying the first ten lines.

  • "--lines" is an option for the "head" command that specifies the number of lines to be displayed. It is used in combination with the "-${count}" argument.

  • "-${count}" is an argument that specifies the number of lines to be displayed. This value is provided by the user and could be replaced with any positive integer.

  • "${filename}" is a placeholder for the name and/or path of the file that you want to display the lines from. This value is also provided by the user and should be replaced with the actual filename.

The "${count}" value is prefixed with a minus sign ("-") to indicate that it represents a negative number. In this context, a negative count means it will display all lines in the file except the last ${count} number of lines. For example, if ${count} is 5, it will display all lines except the last 5.

In summary, running this command will display all lines of a file except the last few lines specified by the negative ${count} value.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the head tool