Now, mv is similar to ln + rm, though, the former will work for cross-filesystem moves (which then just becomes cp + rm), whereas the latter will fail at ln (which does not support cross-filesystem hard links).
–
Chris Jester-YoungJan 28 '10 at 13:16

8 Answers
8

Assuming the files involved are on the same file system, then mv simply changes pointers in the file system, whereas cp copies the entire contents of the file, and rm once again changes pointers. So mv is far more efficient.

@eSKay: No. Two scenarios: 1. The target does not exist. mv just renames the file (same inode as original file). cp makes a new inode for the new file. 2. The target does exist. mv unlinks (removes) the target file, and renames, in one step. cp overwrites the target file's inode.
–
Chris Jester-YoungJan 28 '10 at 13:19

1

Also mv never changes permission or ownership. Imagine you want to move a file from your buddy's homedir to your own homedir. If you mv it you will end up with a file in your homedir that belongs to your buddy. You can't chown or chmod and depending on the permissions not even modify or read it. If you do cp followed by rm the file will belong to you and everything is fine.
–
Ludwig WeinzierlJan 28 '10 at 19:16

The difference is that mv conserves file-attributes while cp by default doesn't, for example setting creation-date to the current date.

To override this default, use "cp -p" to preserve the last data modification, the time of the last access, the user ID and group ID (only if it has permissions to do this),
file permission bits and the SUID and SGID bits.

Yes, mv has a chance of being atomic on the same disk, whereas the combination of cp and rm never has.

This is assuming that mv is implemented using rename(), which is the call that has the guarantee. See, for instance, this newsgroup post, which quotes POSIX:

This rename() function is equivalent
for regular files to that defined
by the ISO C standard. Its inclusion here expands that definition
to
include actions on directories and specifies behavior when the new
parameter names a file that already exists. That specification
requires that the action of the function be atomic.

mv simply changes the filesystem metadata on the file relating to it's name and location, whereas cp creates a seperate copy of the file, which takes much
longer as it must fully read the first file and then write it's contents to another file