Often I want to exchange two folders like this:
$ mv a{,-alt-tmp}
$ mv a{-alt,}
$ mv a-alt{-tmp,}
i.e. the folder “a” becomes “a-alt” and “a-alt” becomes “a”. Is there some bash command to accomplish this? There should be a minimal time gap between the two changes.
I could do something similar with
$ mv a{,-old} && mv a{-new,}
but this doesn’t work with a real exchange of names, since one folder has an other name afterwards.
I’m not sure that you can do this atomically, but the time gap between three calls to
mvin a small script or bash function will be small and likely sufficient for most people’s needs. eg.Be careful, as if there is an open file handle to a file in the a/ directory, after the moving the handle will point to the file that is now in the a-alt/ directory.