当前目录有两个文件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”,这个才是正确的错误信息
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目录
所以会提示不能在自身目录中移动子目录中
mv temp temp2 移动temp目录到temp2目录
所以会提示不能在自身目录中移动子目录中