Philip Rowlands wrote: > On Sun, 30 Aug 2009, James R. Van Zandt wrote: > > > > For the help text, here are some alternatives: > > > > > > if DEST is a directory, then delete it first > > > This isn't what -T does. If DEST is an empty directory then it's > overwritten with the rename(2) system call. Otherwise mv will fail > e.g. if SOURCE isn't a directory or DEST is non-empty.
Let's see... vanzandt:/tmp$ date >source vanzandt:/tmp$ mkdir dest vanzandt:/tmp$ mv -T source dest mv: cannot overwrite directory `dest' with non-directory vanzandt:/tmp$ rm -rf dest vanzandt:/tmp$ touch test vanzandt:/tmp$ mv -T source dest vanzandt:/tmp$ I agree my proposed help text is wrong. However, I think the current description in the info file is wrong too. It says "Do not treat the last operand specially when it is a directory or a symbolic link to a directory." Yet, this is an example where mv fails when DEST is a directory, and succeeds when it is a normal file. So a directory *is* treated differently. The extended discussion on the "Target directory" page says: For example, when the command `mv /tmp/source /tmp/dest' succeeds, there is no guarantee that `/tmp/source' was renamed to `/tmp/dest': it could have been renamed to `/tmp/dest/source' instead, if some other process created `/tmp/dest' as a directory. However, if `mv -T /tmp/source /tmp/dest' succeeds, there is no question that `/tmp/source' was renamed to `/tmp/dest'. I read the last sentence as saying /tmp/source would get renamed as /tmp/dest whether or not some other process had previously created /tmp/dest as a directory. The fact that it fails instead certainly should be stated. (To me it seems a much less useful behavior.) - Jim Van Zandt