2

We are currently doing classic planA.

I want to know which one is better?

Both fileA and fileB exist, with size of ~50-100M.

assume in the same NFS mount in Linux/mac

assume this is a overwrite where both files exist

# planA - we do this way
mv /pathA/fileA /pathB/fileB

# planB
rm /pathB/fileB; mv /pathA/fileB /pathB/fileB

# planB1 - I think is the same as planB, but not sure
unlink /pathB/fileB; ln /pathA/fileA /pathB/fileB
  • 2
    i think simple renaming is the better and fast option. A – Ijaz Ahmad Khan Dec 30 '15 at 13:53
  • Can you even do hardlinks over NFS? (I don't have the environment to try it.) – a CVn Dec 30 '15 at 19:21
  • Yes, we have done a lot of them just to save disk space – Gang Dec 30 '15 at 19:34
9

When it comes to file IO, the expensive task is moving the data around.

If it's within a filesystem (which it would have to be for that ln to work) the difference is moot.

In each case, all that's happening is a directory entry is getting modified to point to a different inode. That'll only be a negligible difference if best, so you're comparing 'how fast do commands start up' really.

But with one caveat - that last command will leave /pathA/fileA in place - it's a hard link, making both directory entries point to the same data.

This might confuse people in future, because if they overwrite fileA, it'll do one thing, and if they edit it it'll do something else.

So just err on the side of simple - stick with just an mv. It won't make much difference overall, and that's the most clear as to what you're actually trying to accomplish.

  • If a unlink /pathA/fileA were added to 'Plan B1', all three operations would be practically equivalent. – Dylan Frese Dec 30 '15 at 20:56

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.