Unix / Linux: Remove Bytes from Beginning of File

Objective: Remove first n bytes from a binary (or text) file on Unix / Linux.

Let’s say that we have a binary file called foo.bin and we need to strip the first 16 bytes from the file. To do that, we can either use the dd or tail utility. dd is the more safer when working on binary files.

To strip the first 16 bytes from the foo.bin file and write it to dd-out.bin file, use the following dd command syntax.

The ibs parameter tells dd to read 16 bytes at a time. The skip parameter means: skip 1 ibs-sized (16 bytes) block at the start of input.

We can verify the header has been stripped by using hexdump on the input and output files.

As you can see, the first 16 bytes 0100 af01 168b 0a47 da6f 3402 236b 7bb3 have been removed from the output file.

To strip the header bytes using tail, use the following syntax.

Note the -c +17 argument to tail. It means output starting with byte 17. The output is written to file tail-out.bin. We can verify the header content using hexdump.

As you can see, both dd-out.bin and tail-out.bin files have the 16-byte header removed.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }