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

I am writing a bash script that should get the header (first 10 bytes) of a file, and then in another section get everything except the first 10 bytes. These are binaries and are likely to have \0 and \n for the first 10 bytes. Most utilities seem to work with ASCII files. What is a good way to achieve this?

+50
bash binary
Dec 10 2018-10-10
source share
3 answers

To get the first 10 bytes, as already noted:

 head -c 10 

To get everything except the first 10 bytes (at least with GNU tail ):

 tail -c+11 
+81
Dec 10 2018-10-10
source share

You can use the dd to copy an arbitrary number of bytes from a binary file.

 dd if=infile of=outfile1 bs=10 count=1 dd if=infile of=outfile2 bs=10 skip=1 
+27
Dec 10 2018-10-10
source share

head -c 10 does the right thing here.

+25
Dec 10 '10 at 16:35
source share



All Articles