GNU bug report logs - #6960
mv refuses to move a symlink over a hard link to the same file

Previous Next

Package: coreutils;

Reported by: Matt McCutchen <matt <at> mattmccutchen.net>

Date: Tue, 31 Aug 2010 21:27:01 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Davide Brini <dave_br <at> gmx.com>
To: bug-coreutils <at> gnu.org
Subject: bug#6960: mv refuses to move a symlink over a hard link to the same file
Date: Tue, 31 Aug 2010 23:48:56 +0100
On Tue, 31 Aug 2010 17:21:08 -0400
Matt McCutchen <matt <at> mattmccutchen.net> wrote:

> If mv is asked to move a symlink over a hard link to the same file, it
> fails with the message, "A and B are the same file".  There is no reason
> why it should complain rather than perform the move.  Example:
> 
> $ ~/coreutils/coreutils.usr/bin/mv --version
> mv (GNU coreutils) 8.5.143-77702
> Copyright (C) 2010 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.
> $ touch New_York
> $ ln New_York localtime
> $ ln -s New_York localtime.new
> $ ls -l
> total 0
> -rw------- 2 matt matt 0 2010-08-31 17:10 New_York
> -rw------- 2 matt matt 0 2010-08-31 17:10 localtime
> lrwxrwxrwx 1 matt matt 8 2010-08-31 17:11 localtime.new -> New_York
> $ ~/coreutils/coreutils.usr/bin/mv localtime.new localtime
> /home/matt/coreutils/coreutils.usr/bin/mv: `localtime.new' and
> `localtime' are the same file

A simpler example is something like

$ touch New_York
$ ln -s New_York New_York.sym
$ mv New_York.sym New_York 
mv: `New_York.sym' and `New_York' are the same file

I think the reason is that when the source is a symbolic link, mv operates
on the symlink itself, not the file it points to. So, it can't rename the
symlink, because if successful that would imply having two entries named
"New_York" in the same directory. If this is really the reason for the
error, the error message could probably be improved.

-- 
D.




This bug report was last modified 13 years and 179 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.