vendredi 27 février 2015

How to delete part of a binary file without copying


I need to delete the first 2 bytes of a 6MB file. However, this is an embedded Linux with only 32 Mbytes RAM and less than 1 MB free flash memory.


I tried using dd, as:


1 - # dd bs=1 skip=2 count=1022 if=input of=ouput_1


2 - # dd bs=1024 skip=1 if=input of=ouput_2


3 - # rm -rf input


4 - # (dd if=ouput_1 ; dd if=ouput_2) > ouput


5 - # rm -rf ouput_1 ouput_2


With all files under the /tmp (mounted as tmpfs on RAM), my problem is that just before lines 3 and 5, the memory needed is 12 Mbyte (2x6MB), and the process sometimes fail and gives an "Not enough memory" error.


Is there a way I can remove the first 2 bytes without allocating twice the size of the file ? Can I use dd (or any other) to cut a binary file 'in place' ?



Aucun commentaire:

Enregistrer un commentaire