Edit: I revised this answer to indicate the pros and cons.
Some manual pages are rather terse because the information is mentioned in the corresponding Info manual.
Man
-f, --force
do not prompt before overwriting
Info
Note: mv
will only replace empty directories in the destination. Conflicting populated directories are skipped with a diagnostic.
[...]
-f,
--force
If a destination file exists but is normally unwritable, standard input is a terminal, and the -f
or --force
option is not given, mv
prompts the user for whether to replace the file. (You might own the file, or have write permission on its directory.) If the response is not affirmative, the file is skipped.
mv
cannot replace non-empty directories but can overwrite existing files owned by the user which are normally unwritable (the owner do not have write permissions, c.f. the quotation).
foo
|-- ajax
`-- bar
`-- ajax
You can merge the directories foo/ajax
and foo/bar/ajax
either keeping all files or overwritting identical files as proposed by @muru.
However, this method is unsuitable if the contents of these directories are unrelated. It may be not obvious at first glance so let's see a new tree.
prompt% tree home/network
home/network/
├── data
│ ├── img
│ │ └── demo.png
│ └── src
│ ├── contact.pdf
│ └── report.pdf
├── hardware
│ ├── api
│ ├── docs
│ └── src
│ └── driver.c
├── misc
│ └── src
│ └── init.py
├── README
└── src
├── main.c
└── manager.c
We can move the contents of network/data
into network
and choose to merge directories having the same name (c.f. below).
prompt% cp -ab home/network/data/* home/network
prompt% rm -r home/network/data/*
prompt% tree home/network
home/network/
├── data
├── hardware
│ ├── api
│ ├── docs
│ └── src
│ └── driver.c
├── img
│ └── demo.png
├── misc
│ └── src
│ └── init.py
├── README
└── src
├── contact.pdf
├── main.c
├── manager.c
└── report.pdf
As we can see, the final directory network/src
may contain unrelated files after moving. If it is undesirable, we can rename files and directories having the same names after moving.
prompt% mv -b -S "_data" home/network/data/* home/network
prompt% tree home/network
home/network/
|-- README
|-- data
|-- hardware
| |-- api
| |-- docs
| `-- src
| `-- driver.c
|-- lib
| `-- demo.png
|-- misc
| `-- src
| `-- init.py
|-- src
| |-- contact.pdf
| `-- report.pdf
`-- src_data
|-- main.c
`-- manager.c
mv
complains for reasons, in the end it depends what exactly you want to happen when there are folders and files to be overwritten... There are also some corner cases to take note of, e.g. what happens when there is abar/bar/
, or other conflicts.