linux shell mv/cp 错误: will not overwrite just-created <filename> with <sameFilename> 解决方法

运行shell脚本时,mv/cp时出现如下提示:

mv: will not overwrite just-created <filename> with <sameFilename>
cp: will not overwrite just-created <filename> with <sameFilename>

这种现象发生的原因是:移动或复制两个或多个文件名相同的文件到同一个目录下。
这只会mv/cp第一个遇到的文件,拒绝mv/cp第二个同名文件(这会覆盖另一个文件,从而有丢失用户数据的风险)。

> mkdir a b c
> touch a/file
> touch b/file
> mv a/file b/file c/
mv: will not overwrite just-created `c/file' with `b/file'

执行上述命令,a/file成功移动到c中,而b/file没有被移动。

猜你喜欢

转载自blog.csdn.net/whatday/article/details/113773188