How to display all lines except the last?

To display all lines of a file except the last few lines using the head command, you can use the -n option with a negative number. Here's how to do it:

Syntax:

head -n -[number_of_lines] filename

Example:

  1. Display all lines except the last 3 lines:
    head -n -3 /path/to/your/file.txt

Explanation:

  • The -n -3 option tells head to show all lines except the last 3 lines of the specified file.

Note:

  • This feature is particularly useful when you want to review most of a file's content while excluding the most recent entries, such as in log files.

If you have any further questions or need more examples, feel free to ask!

0 Comments

no data
Be the first to share your comment!