How to move and overwrite subdirectories (and files) to parent directory?

You will have to copy them to the destination and then delete the source, using the commands cp -r * .. followed by rm -rf *.

I don't think you can "merge" directories using mv.


rsync would probably be a better option here. It's as simple as rsync -a subdir/ ./.

My test tree in filename:contents format:

./file1:root
./file2:root
./dir/file3:dir
./dir/file4:dir
./subdir/dir/file3:subdir
./subdir/file1:subdir

Running rsync:

$ rsync -a -v subdir/ ./
sending incremental file list
./
file1
dir/
dir/file3

Gives:

./file1:subdir
./file2:root
./dir/file3:subdir
./dir/file4:dir
./subdir/dir/file3:subdir
./subdir/file1:subdir

And then, to emulate mv, you probably want to remove the source directory:

$ rm -r subdir/

Giving:

./file1:subdir
./file2:parent
./dir/file3:subdir
./dir/file4:dir

If this is wrong, can you please provide a similar example (e.g. using my test tree from near the top of this answer) with the desired result?


rsync can delete the source after copying with the --remove-source-files parameter.

From the rsync man page:

--remove-source-files   sender removes synchronized files (non-dir)