mv: "Directory not Empty" - 如何将目录与 `mv` 合并?
mv: "Directory not Empty" - how do you merge directories with `mv`?
我最近尝试将我的个人博客网站部署到我的远程服务器上。当我试图通过执行 mv
将几个文件和目录移动到另一个地方时,发生了一些意想不到的错误。命令行回显“目录不为空”。在谷歌搜索后,我再次尝试使用“-f”开关或“-v”,结果相同。
我登录的是root账号,过程在这里:
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)
我终于找到了解决办法。因为 /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
如果您有 sub-directories 而“mv”不工作:
cp -R source/* destination/
rm -R source/
我更喜欢
而不是cp
或rsync
复制目录
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}
进行清理
我最近尝试将我的个人博客网站部署到我的远程服务器上。当我试图通过执行 mv
将几个文件和目录移动到另一个地方时,发生了一些意想不到的错误。命令行回显“目录不为空”。在谷歌搜索后,我再次尝试使用“-f”开关或“-v”,结果相同。
我登录的是root账号,过程在这里:
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)
我终于找到了解决办法。因为 /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
如果您有 sub-directories 而“mv”不工作:
cp -R source/* destination/
rm -R source/
我更喜欢
而不是cp
或rsync
复制目录
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}