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.
On the same filesystem, 'mv' doesn't actually copy the data, it just remaps the inode, so it is far faster than cp. Rsync will be slower than cp since, it still needs to copy the entire file - and it has additional overhead (even if minor in this case).
"mv" is faster than "cp". by doing "cp" we are creating another 'inode' structure for that file. while doing "mv" ... we are just renaming tte filename attribute of the inode structure.
You can use the mv command to move files within the same file system or between file systems. Whether you are working in one file system or across file systems, the mv command copies the file to the target and deletes the original file.
To copy directory dir1 with all the files and subdirectories to a different directory, issue “cp -r dir1 <path_to_new_dir>”. “mv” command is used to move or rename files and directories. It also requires at least two arguments. To rename file file1 to file2, issue “mv file1 file2” command.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With