7

Let's say I have two flash memory devices 1GB capacity each. Let's also say each device contains one big file ~ 1GB size. Assuming, I have limited (64MB) RAM and no hard disk drive, what is the shortest way to swap this two files ?

I mean: if file a is on device A and b is on device B, I want swap operation to place a on B and b on A.

I know there is no exact linux tool to do that according to this discussion.

I am interested in shortest way to achieve my goal. If that way will be too long, I probably will have to implement my own dedicated solution that will perform swap chunk by chunk, am I right ?

  • When copying the files chunk by chunk, you could use something like this to convert the chunks you've already copied to sparse holes to free space. – n.st Mar 26 '14 at 22:49
2

As long as both drives are full, or almost full, I doubt there is a pretty solution. It should be possible to loop over dd commands though. Something like

#This code is completely untested, 
#do NOT just copy paste and use it without proper testing
while [[ $((i*chunkSize)) -lt fileSize ]]; do
  dd skip=$i seek=$i bs=$chunkSize count=1 if=fileA of=tmpFileInMemory
  dd skip=$i seek=$i bs=$chunkSize count=1 if=fileB of=FileA
  dd skip=$i seek=$i bs=$chunkSize count=1 if=tmpFileInMemory of=fileB
done

Some checks are needed for when fileA and fileB have different sizes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.