MV:"Directory not Empty" - 如何将目录与"MV"合并?

  • 本文关键字:MV 合并 Directory not Empty mv
  • 更新时间 :
  • 英文 :


我最近尝试将我的个人博客网站部署到远程服务器。当我试图通过执行mv将一些文件和目录移动到另一个地方时,发生了一些意外的错误。命令行回显";目录不为空";。在谷歌上搜索后,我再次尝试使用"-f"开关或"-v",结果相同。我登录了帐户,过程如下:

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

有人知道为什么吗?

(我运行的是Ubuntu 14.04)

如果您有子目录和"mv";不工作:

cp -R source/* destination/ 
rm -R source/

我更喜欢,而不是通过cprsync复制目录

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

移动文件(实际上是重命名文件)并覆盖现有文件。所以它足够快了。但是,当${source_path}包含空子文件夹时,可以通过rm -rf ${source_path} 进行清理

我终于找到了解决方案。因为/var/www/html/wp-content已经存在,所以当您尝试在那里复制/var/www/html/wordpress/wp-content时,会发生Directory not Empty的错误。因此,您需要将/var/www/html/wordpress/wp-content/*复制到/var/www/html/wp-content。只需执行以下操作:

mv /var/www/html/wordpress/wp-content/* /var/www/html/wp-content
rmdir /var/www/html/wordpress/wp-content
rmdir /var/www/html/wordpress

最新更新