4 ms·
I use this technique a lot: mv thing thing.old && mv thing.new thing It works whether the thing is a file or a directory; I have an automatic backup called
by fexl 17y ago
I use this technique a lot:
mv thing thing.old && mv thing.new thing
It works whether the thing is a file or a directory; I have an automatic backup called thing.old; I suppose it's reasonably atomic; and I can do it in ssh with no worries about losing the network connection in between the two moves.
- gchpaco 17y agoIt's not atomic at all although you're unlikely to notice in most situations. Not what I would use in a script, though.
- fexl 17y agoRight ... "reasonably atomic" I say. Come to think of it, I'm not sure what I'd use in a script for this.
- deleted 17y ago[deleted]
- fexl 17y agoOn second thought if you use symlinks I'm pretty sure this is atomic: ln -Tfs $dir $symlink Where $dir is the name of a directory and $symlink is the name of a symlink.