How do I view the first few bytes?

0150

To view the first few bytes of a file in Linux, you can use the head command with the -c option. This allows you to specify the number of bytes you want to display from the beginning of the file.

Command Syntax

head -c [NUM] [file]
  • -c [NUM]: Replace [NUM] with the number of bytes you want to see.
  • [file]: Specify the path to the file you want to read.

Example Usage

If you want to view the first 5 bytes of a file named example.txt, you would run:

head -c 5 example.txt

Output

This command will display the first 5 bytes of the file. For instance, if example.txt contains the text "Hello, World!", the output would be:

Hello

Additional Notes

  • If you omit the -c option, head defaults to displaying the first 10 lines of the file instead of bytes.
  • This method is particularly useful for quickly checking file headers or binary data.

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

0 Comments

no data
Be the first to share your comment!