Odd wording it docs for shutil.move?

Chris Warrick kwpolska at gmail.com
Fri Mar 3 12:22:04 EST 2017

On 3 March 2017 at 18:13, Grant Edwards <grant.b.edwards at gmail.com> wrote:
> At https://docs.python.org/2/library/shutil.html it says:
>  shutil.move(src, dst)
>     Recursively move a file or directory (src) to another location
>     (dst).
>     [...]
>     If the destination is on the current filesystem, then os.rename()
>     is used. Otherwise, src is copied (using shutil.copy2()) to dst
>     and then removed.
> What does the current filesystem have to do with anything?
> Surely, what matters is whether <src> and <dst> are on the same
> filesystem?

For the same reason it matters for /bin/mv. If the source and target
are on the same filesystem, the files are just renamed, which is
usually instantaneous (only file metadata needs to be changed). But if
they are on different filesystems, “move” really means “copy and
delete original”, which takes much longer.

>From macOS/BSD manpages, mv(1):
     As the rename(2) call does not work across file systems, mv uses
cp(1) and rm(1) to accomplish the move.

See also: https://en.wikipedia.org/wiki/Mv

Chris Warrick <https://chriswarrick.com/>

More information about the Python-list mailing list