How to view the beginning of files?

086

To view the beginning of files in a terminal, you can use the head command. Here’s how to do it:

Basic Usage of head:

  1. View the First 10 Lines (Default):
    By default, head displays the first 10 lines of a file.

    head filename.txt
  2. View a Specific Number of Lines:
    You can specify the number of lines to display using the -n option.

    head -n 5 filename.txt

    This command will show the first 5 lines of filename.txt.

  3. View a Specific Number of Bytes:
    You can also view a specific number of bytes using the -c option.

    head -c 50 filename.txt

    This command will display the first 50 bytes of filename.txt.

Example:

To view the first 10 lines of a file named example.txt, you would run:

head example.txt

Additional Options:

  • You can combine head with other commands using pipes to filter or process data further.
  • For example, to view the first 10 lines of the output from another command:
    ls -l | head

Using the head command is a straightforward way to quickly access the beginning of files in a terminal.

0 Comments

no data
Be the first to share your comment!