Reputation: 14021
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)
Upvotes: 24
Views: 101867
Reputation: 1622
If you have sub-directories and "mv" is not working:
cp -R source/* destination/
rm -R source/
Upvotes: 42
Reputation: 32650
Try the mmv
tool instead of mv
.
Collisions and Deletions
When any two or more matching files would have to be moved, copied, or linked to the same
target filename, mmv detects the condition as an error before performing any actions.
Furthermore, mmv checks if any of its actions will result in the destruction of existing
files. If the -d (delete) option is specified, all file deletions or overwrites are done
silently.
Upvotes: 0
Reputation: 126
I use rsync
normally for copying. In case you are running out of space on your hard disk and your destination file structure is more complex (so you can't or don't want to simply delete the destination folder to free the space for moving), you can use the option --remove-source-files
(for more info about this option on superuser) of rsync
! It will asynchronously delete the source files directly after the rsyncing to destination. So you just don't need the double space of disk space, instead it is only a relatively small amount of disk space during the rsyncing. After the rsyncing all disk space is freed from the transferred files. So you could more easily achieve your goal by:
$ rsync -avh --remove-source-files --info=progress2 --size-only /var/www/html/wordpress/* /var/www/html
In this case I added a progress bar, rsynced with all file attributes and verbosed them and only rsynced files which differ in size (which does not matter here as rsync "touches" every file and therefore afterwards it is deleted)
Upvotes: 1
Reputation: 3372
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}
Upvotes: 2
Reputation: 14021
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
Upvotes: 3