Subject: bug#20091: mv command

From: "Rogers, Charles (MAN-Corporate-CON)" <[email-masked]>
Date: Thu, 12 Mar 2015 22:10:22 +0000

Thank you all so much for the explanation.   It is as you describe.

1.  We had insufficient permissions on the source directory

2.  The destination directory was indeed on a different file system

So, our question is answered, and again thanks.

Charles Rogers          (  on behalf of  Renata Karciauskaite )

-----Original Message-----
From: Bob Proulx [mailto:[email-masked]]
Sent: Thursday, March 12, 2015 1:46 PM
To: Rogers, Charles (MAN-Corporate-CON); [email-masked]
Subject: Re: bug#20091: mv command

Pádraig Brady wrote:

> Charles Rogers wrote:

> > Is it ever possible for the mv command ( without using the –u

> >option ) to leave the file(s) in the source directory, while also

> >copying to the destination directory?

> >...

> > Any  comments appreciated!

Your description implies that your destination is on a different file system from your source.  Is this one one source directory or multiple source directories being copied at one time?

In order for mv to decide it needs to copy a file it would need to detect that the destination directory is on a different file system from the source directory.  If so then mv will copy the file to the destination location and remove the file from the source location.

The mv documentation describes this in some detail.

       ‘mv’ can move any type of file from one file system to another.

    Prior to version ‘4.0’ of the fileutils, ‘mv’ could move only

    regular files between file systems.  For example, now ‘mv’ can

    move an entire directory hierarchy including special device files

    from one partition to another.  It first uses some of the same

    code that’s used by ‘cp -a’ to copy the requested directories and

    files, then (assuming the copy succeeded) it removes the

    originals.  If the copy fails, then the part that was copied to

    the destination partition is removed.  If you were to copy three

    directories from one partition to another and the copy of the

    first directory succeeded, but the second didn’t, the first would

    be left on the destination partition and the second and third

    would be left on the original partition.

Copying files across file systems and removing them from the source is a non-atomic operation.  There is always the possibility that the process will be stopped (possibly by being killed or other

possibilities) after it has copied a file to the destination but before it has removed the file from the source location.  It is not possible to perform an atomic move across different file systems.  Any of those possibilities should result in mv exiting non-zero and returning an error status to the caller.  Most possibilities (not SIGKILL which cannot be trapped) will result in mv printing an error message to stderr.  Generally if mv has an error there should be an error message and a non-zero exit status returned to the caller.

Bob