mv命令发疯了

时间:2014-09-03 10:32:36

标签: linux shell unix mv

这是脚本,我已经挑出了我认为导致最近问题的块

mv sourcefile targetfile > /dev/null  

我知道mv默认会覆盖,而不会要求确认目标文件是否存在。因此,脚本(上图)是正确的。

mv: try to overwrite `targetfile', overriding mode 0644 (rw-r--r--)?

它提示/要求确认覆盖的唯一时间是使用-i选项,在这种情况下不使用。它并不总是发生。偶尔弹出一次

那么,为什么它会这样呢?

这是我的MV版

mv (GNU coreutils) 8.12
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Parker, David MacKenzie, and Jim Meyering.

2 个答案:

答案 0 :(得分:5)

根据man页面,-f选项有此目标:

       -f, --force
          do not prompt before overwriting

答案 1 :(得分:1)

我找到了原因。这是由于权限。

我已将目录权限更新为chmod a+w <directory>

其他可能的解决方案是在mv命令之前添加rm -f targetfile

当然,GHugo添加-f选项是正确的