It seems mv -T is a GNU extension to mv.
Is there a robust way (race-free, portable, and otherwise without "gotchas") to do the equivalent of mv -T dir1 dir2?
To be clear:
I DO NOT want this to ever result in
dir2/dir1. Ifdir2exists, I want the command to fail. Ifdir1is moved at all, it must becomedir2.I DO NOT want to move out every child one-by-one. I want to move the directory itself.
I DO want to avoid race conditions. It's trivial to test if
dir2exists first, but then it might be created after the check but before the move.