1

Suppose that I have only the following in ~/foo:

.
..
foo

With file managers if I cut the subfolder foo and paste it into ~ it automatically replaces the contents of ~/foo with that of ~/foo/foo.

But is there a native command-line tool to do so, although I can achieve the goal with a function, too?

1

I don’t know any way to do it in one step, but the easiest way around the problem is to remove the problem.  The fact that the two directories have the same name is a problem; so, rename one of them:

mv foo foo2  &&  mv foo2/foo foo  &&  rmdir foo2
  • 1
    Or with GNU mv: mv -iT foo/foo foo2 && mv -T foo2 foo. One question would be: which foo would we like to preserve the metadata of? – Stéphane Chazelas Apr 29 '18 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy