I have an empty file (only zeroes are in it) of size 9,0KB and I need to write another file (with size 1,1KB) to it, but the first file must not lose its size or the rest of its contents. So if the whole file is 00000000000000...
now, I need to write second file in it and leave the zeroes as they are. I have tried to use dd
, but I haven't succeed – file resizes.
dd if=out/one.img of=out/go.img
Does anybody know how can I do it?
Best Answer
To overwrite the start of the destination file without truncating it, give the
notrunc
conversion directive:If you wanted the source file's data appended to the destination, you can do that with the
seek
directive:This tells
dd
that the block size is 1 kiB, so that theseek
goes forward by 9 kiB before doing the write.You can also combine the two forms. For example, to overwrite the second 1 kiB block in the file with a 1 kiB source:
That is, it skips the first 1 kiB of the output file, overwrites data it finds there with data from the input file, then closes the output without truncating it first.