linux mv问题

当前目录有两个文件temp temp2
命令执行顺序:
cp -r temp temp2
mv temp temp2
执行失败:
mv: cannot move 'temp' to a subdirectory of itself 'temp2/temp'

想要的效果是执行mv命令的时候替换。
用命令rm-rf temp2/temp删除temp2再mv肯定可以

问题的目的就是知道为什么不可以。

系统提示不能把temp移动到自己的子目录里面,证明temp2 和temp有隶属关系,这样的mv操作时不会成功的。追问

为什么cp有依赖关系,使用cp命令是需要什么参数能去掉这种关系使得mv够强制替换。

追答

cp -r ./temp ./temp2/
mv ./temp ./temp2/
试试

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-08-31
不能先删除 temp2 吗?

rm -rf temp2
mv temp temp2

======

我重现了一下:

mkdir temp temp2
touch temp/README
cp -r temp temp2
mv temp temp2
mv: overwrite ‘temp2/temp’? y
mv: cannot move ‘temp’ to ‘temp2/temp’: Directory not empty

上面提示目录非空。然后我如果不建立 README 文件,mv 就成功了。我的 coreutils 版本是 8.17-3 ,会不会是你的 coreutils 版本过低?

这个帖子: 指出 coreutils 6.9 以上错误信息会是“Directory not empty”,这个才是正确的错误信息
第2个回答  2012-08-30
cp -r temp temp2 复制temp目录到temp2目录中
mv temp temp2 移动temp目录到temp2目录
所以会提示不能在自身目录中移动子目录中

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网