0

If I'm working just inside one partition, could I move files around? The idea is to refresh an SD card against bit rot, but without moving the files out and in again.

Quora Feans
  • 3,866

2 Answers2

1

mv will simply alter the file's metadata. If you want a fresh copy of the file written to disk, mv the file to a temporary new location, and cp it back in place. Once you have verified a successful copy, you can rm the original.

DopeGhoti
  • 76,081
0

If you have the space, use recursive cp or rsync to make a second copy in the partition, then delete the first.

If not you could copy each file over itself. The system and ssd should not notice that the data is the same, so should allocate a new block for it. You can use dd conv=notrunc for this. It has the advantage of preserving hardlinks, and even if interrupted the data should be undamaged. Eg

dd if=myfile of=myfile conv=notrunc

You would want to preserve file attributes. For the modification time, save it first with touch -r myfile tmp, then restore it after with the reverse touch -r tmp myfile. There remains directories and symbolic links that won't get refreshed.

meuh
  • 51,383