Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get only the first ten bytes of a binary file

Tags:

bash

binary

I am writing a bash script that needs to get the header (first 10 bytes) of a file and then in another section get everything except the first 10 bytes. These are binary files and will likely have \0's and \n's throughout the first 10 bytes. It seems like most utilities work with ASCII files. What is a good way to achieve this task?

like image 684
User1 Avatar asked Dec 10 '10 16:12

User1


People also ask

How do I view bytes of a file?

Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window. In this example, the chrome. jpg file is 18.5 KB (19,032 bytes), and that the size on disk is 20.0 KB (20,480 bytes).


2 Answers

To get the first 10 bytes, as noted already:

head -c 10 

To get all but the first 10 bytes (at least with GNU tail):

tail -c+11 
like image 190
psmears Avatar answered Sep 28 '22 04:09

psmears


head -c 10 does the right thing here.

like image 23
moonshadow Avatar answered Sep 28 '22 05:09

moonshadow