[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#20091: mv command

From: Bob Proulx
Subject: bug#20091: mv command
Date: Thu, 12 Mar 2015 11:45:49 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]