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

User1 picture User1 · Dec 10, 2010 · Viewed 64.2k times · Source

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?

Answer

psmears picture psmears · Dec 10, 2010

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