On Monday 29 June 2009 06:03:36 leledumbo wrote:
> > You've said to move a directory A/C and a directory B/C to the
> > current working directory. I don't think that is want you meant
> > to do.
> Actually, it is.
Really? You do astound me! However, if that *really* is what you
want, this will get the job done:
$ rm -rf ./C && mv A/C . && rm -rf ./C && mv B/C .
but then why go to this length? You might just as well:
$ rm -rf A/C ./C && mv B/C .
which is a simpler way to achieve identically the same objective.
Now, tell me again: is that *really* what you wanted to do? I think
not, and that Earnie was quite right; you really wanted to *merge*
the *content* of two existing directories into a common tree, while
removing the originals in the process, which you might achieve with:
$ rm -rf ./C && mv A/C ./C && mv B/C/* ./C
However, this will still fail, if A/C and B/C have any similarly
named subdirectory, (at any level in the hierarchy), which is not
empty in the original A/C tree.
> > With more modern systems, where cp supports the `-p' and `-r'
> > options, (as MSYS' cp does), you could also use (untested):
> > $ mv -f A/C . && cp -prf B/C/* C && rm -rf B/C
> Aha! Good idea, I'll try it.
Do note that the `-f' option to `mv' is pretty much redundant here;
in the command:
$ mv -f src dest
`-f' takes effect only if `dest' represents an existing *file* or
*empty* directory, for which you lack write permission, but you do
have permission to `chmod' it, to make it writeable, so that it may
be unlinked; a *non-empty* directory can never be unlinked, even if
you do have write permission, unless you first recursively remove
all of its content, (which `mv' will never do for you).