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' ?
tail -c +3
? – jimmij Feb 26 '15 at 23:45tail
with binary files. Plus, I will still pipe the output to another file, which will will still take space in memory. – srd Feb 27 '15 at 00:09filtered.dump
, reads it and outputs to another filetrimmed.dump
. This question explicitly states that there is not enough disk-space to do that. In that case we can do the same thing withdd
, withif=
andof=
equal, but an additional step of truncating the last two bytes. – Digital Trauma Feb 27 '15 at 00:10grep
would possibly complicate the situation in this specific question – Digital Trauma Feb 27 '15 at 00:15grep
was just an example in that earlier question, the difficulty is the edit in place. However robustness to power failures is a twist that I think has never come up on this site. – Gilles 'SO- stop being evil' Feb 27 '15 at 00:17fallocate
-based answer to the related question. If you are using a recent Linux kernel and the supported filesystem; could you try it? – jfs Feb 27 '15 at 13:32