7

Here is the script and I have singled out the block that I believe is causing the recent problem

mv sourcefile targetfile > /dev/null  

I know for a fact that mv will by default overwrite without asking for confirmation if the destination file exists. Therefore, the script (above) is right.

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

The only time it will prompt/ask for confirmation to overwrite is with an –i option, which in this case is not used. It is not always happening. Just pops up once in a while

So, why is it behaving this way?

This is my mv version

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.
Srini V
  • 11,045
  • 14
  • 66
  • 89
  • You might get some more inputs on http://unix.stackexchange.com/questions/87605/is-there-a-way-to-make-mv-fail-silently – linux_fanatic Sep 03 '14 at 10:47
  • 3
    "goes crazy" isn't very descriptive about what actually happens. Does it hang, exit, cause all the memory in your system to be allocated, cause elephants to fly out of your monitor...? – Vicky Sep 03 '14 at 10:58
  • @Vicky I know for a fact that mv will by default overwrite without asking for confirmation if the destination file exists. The only time it will prompt/ask for confirmation to overwrite is with an –i option, which in this case is not used. Which means the script would wait all day for a user input. This is the reason for craziness. – Srini V Sep 03 '14 at 11:01

2 Answers2

8

According to man page, the -f option has this goal:

       -f, --force
          do not prompt before overwriting
GHugo
  • 2,584
  • 13
  • 14
2

I found the reason. It was due to permissions.

I have updated the directory permissions as chmod a+w <directory>

Other possible solutions are adding a rm -f targetfile before the mv command.

Ofcourse GHugo was correct to add -f option

Srini V
  • 11,045
  • 14
  • 66
  • 89