1

My Environment:

CentOS 6.5

I need to extract some part of the ELF file.

When I use dd command as follows, I have no problem:

$dd if=a.out of=a.cut1 bs=1 skip=16    

On the other hand, when I use cut command as follows, the created file has much less size than I expected:

$cut --bytes=16- a.out > a.cut2


For example, I created a.out by compiling the following sample c program with gcc (v. 4.4.7):
#include <stdio.h>

int main()
{
    printf("Hello world\n");
}

Then, I execute dd and cut commands as above, I have files with following sizes:

a.out - 6415 bytes
a.cut1 - 6399 bytes
a.cut2 - 6356 bytes

I wonder why the cut command reduces the size more than I specified.

scai
  • 20,297
  • 4
  • 56
  • 72
sevenOfNine
  • 1,509
  • 16
  • 37

1 Answers1

6

cut will skip the first 16 bytes from each line whereas dd doesn't care about lines and skips just the first 16 bytes from the whole file.

If the file contains newlines - which is perfectly valid for binary files - then cut will yield a different result than dd.

scai
  • 20,297
  • 4
  • 56
  • 72