Monday, August 1, 2011

A very bizarre behavior (bug) of "mv" command

I spend all the afternoon to find this bizarre behavior (bug) of "mv" command.

Let us say we have a directory of "source" with files "a" and "b", and we want to move it to "dest/sub/". So the final should look like "dest/sub/source/...". The command should be simple enough "mv source dest/sub".

Well, this works fine when "dest/sub" exists. When we only have "dest", a sub directory "sub" is automatically created, however, files ("a" and "b") are directly copied over instead of the directory "source".

It is like this in Linux (CentOS5.4) "GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)", as well as Mac OS 10.6 "GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)".