简体   繁体   中英

mv command goes crazy

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.

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

       -f, --force
          do not prompt before overwriting

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM