0

I am trying to continuously move many files (~ 10 000 each minute) from /ramdisk to normal /ssd , but not all files are there.

When the mv /ramdisk/file55 /ssd/file55 fails because source is not there, does it attempt to write anything in the destination at all ?

I am asking because I am worried it would wear off the destination SSD, that is why most of these files are kept in /ramdisk

2

The only real way to answer this is to look through the source code. Implementations could vary.

In particular, I assume by mv you mean the one provided by GNU Coreutils.

I'm not confident that I understand all the nuances in their mv code, but I can note these facts:

  • In src/mv.c there is a function do_move(const char *source, const char *dest, const struct cp_options *x) which is presumably the main driver for mv. That function invokes another function called copy.
  • In src/copy.c, the copy function invoked by do_move is basically a wrapper to another function called copy_internal.
  • At the top of the copy_internal function it attempts to stat the source file. If that fails, it bails out without doing anything.

Therefore, I think it is safe to answer:

Attempting to mv a non-existent file will not affect the destination until various checks have passed.

  • 1
    thank you, yes, the --version mentions mv (GNU coreutils) 8.21 – adrianTNT Jan 10 at 0:52
  • @adrianTNT Cool. My answer is based on the code for coreutils 8.30. – cryptarch Jan 10 at 0:54

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.