18

I tried to deploy my personal blog website to my remote server recently. When I tried to move a few files and directories to another place by executing mv, some unexpected errors happened. The command line echoed "Directory not Empty". After doing some googling, I tried again with '-f' switch or '-v', the same result showed. I logged in on the root account, and the process is here:

root@danielpan:~# shopt -s dotglob
root@danielpan:~# mv /var/www/html/wordpress/* /var/www/html
mv: cannot move `/var/www/html/wordpress/wp-content` to `/var/www/html/wp-content`: 
Directory not empty
root@danielpan:~# mv -f /var/www/html/wordpress/* /var/www/html
mv: cannot move `/var/www/html/wordpress/wp-content` to `/var/www/html/wp-content`:
Directory not empty

Anybody know why?

(I'm running Ubuntu 14.04)

TamaMcGlinn
  • 2,840
  • 23
  • 34
SilentKnight
  • 13,761
  • 19
  • 49
  • 78
  • There are good answers on unix.stackexchange [here](https://unix.stackexchange.com/questions/127712/merging-folders-with-mv). – TamaMcGlinn Sep 01 '20 at 10:06

3 Answers3

29

If You have sub-directories and "mv" is not working:

cp -R source/* destination/ 
rm -R source/
humble_barnacle
  • 460
  • 1
  • 4
  • 19
John Tribe
  • 1,407
  • 14
  • 26
3

Instead of copying directories by cp or rsync, I prefer

cd ${source_path}
find . -type d -exec mkdir -p ${destination_path}/{} \;
find . -type f -exec mv {} ${destination_path}/{} \;
cd $oldpwd

moves files (actually renames them) and overwrites existing ones. So it's fast enough. But when ${source_path} contains empty subfolders you can cleanup by rm -rf ${source_path}

mr NAE
  • 3,144
  • 1
  • 15
  • 35
2

I found the solution finally. Because the /var/www/html/wp-content already exists, then when you try to copy /var/www/html/wordpress/wp-content there, error of Directory not Empty happens. So you need to copy /var/www/html/wordpress/wp-content/* to /var/www/html/wp-content. Just execute this:

mv /var/www/html/wordpress/wp-content/* /var/www/html/wp-content
rmdir /var/www/html/wordpress/wp-content
rmdir /var/www/html/wordpress
SilentKnight
  • 13,761
  • 19
  • 49
  • 78
  • 14
    which fails if the target directory's wp-content already contains some non-empty directory to which you intended to add files. – TamaMcGlinn Sep 01 '20 at 09:03