2014-09-03 198 views
3

这里是剧本,我都挑出来,我相信是造成近期问题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. 
+0

你可能会得到一些http://unix.stackexchange.com/questions/87605/is-there-a-way-to-make-mv更多的输入 - 无声无息地 – 2014-09-03 10:47:35

+2

“变得疯狂”对于实际发生的事情并不是非常具有描述性。它会挂起,退出,导致系统中的所有内存被分配,导致大象飞出显示器......? – Vicky 2014-09-03 10:58:39

+0

@Vicky我知道一个事实,如果目标文件存在,默认情况下mv将不需要确认就会覆盖。它会提示/要求确认覆盖的唯一时间是使用-i选项,在这种情况下不使用。这意味着脚本会一整天等待用户输入。这是疯狂的原因。 – SriniV 2014-09-03 11:01:25

回答

3

man页面时,-f选项有这个目标:

 -f, --force 
      do not prompt before overwriting 
0

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

我已经更新了目录权限为mv命令前chmod a+w <directory>

其他可能的解决方案是增加一个rm -f targetfile

Ofcourse GHugo是正确添加-f选项