Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mv command goes crazy

Tags:

linux

shell

unix

mv

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.
like image 289
SriniV Avatar asked Sep 03 '14 10:09

SriniV


People also ask

Why is mv so fast?

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).

Is mv quicker than cp?

"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.

Does mv copy or move?

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.

What is the difference between cp and mv command in Linux?

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.


2 Answers

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

       -f, --force
          do not prompt before overwriting
like image 121
GHugo Avatar answered Oct 17 '22 02:10

GHugo


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

like image 2
SriniV Avatar answered Oct 17 '22 02:10

SriniV