Bug 201083

Summary: mv a.file b.file /doesnotexist results in usage message; not user friendly
Product: Base System Reporter: Enji Cooper <ngie>
Component: binAssignee: Jilles Tjoelker <jilles>
Status: Closed FIXED    
Severity: Affects Many People CC: emaste, jilles
Priority: --- Flags: jilles: mfc-stable10+
jilles: mfc-stable9-
jilles: mfc-stable8-
Version: CURRENT   
Hardware: Any   
OS: Any   

Description Enji Cooper freebsd_committer freebsd_triage 2015-06-23 21:55:03 UTC
FreeBSD punts out a usage message with mv when the target doesn't exist:

$ uname -a
FreeBSD wkstn-fbsd-ngie 11.0-CURRENT FreeBSD 11.0-CURRENT #3 r275919+fef312b(projects/building-blocks): Thu Dec 18 16:14:11 PST 2014     ngie@wkstn-fbsd-ngie:/usr/obj/usr/src/sys/GENERIC-WITHOUT-WITNESS  amd64
$ which mv
/bin/mv
$ mv src/test_bug_135934.c src/test_bug_149417.sh src/test_bug_151050.sh src/test_new_build.sh idontexist
usage: mv [-f | -i | -n] [-hv] source target
       mv [-f | -i | -n] [-v] source ... directory

Fedora Linux 20 on the other hand has a more usable error message:

$ cat /etc/redhat-release 
Fedora release 20 (Heisenbug)
$ mv t_gdtoa.c /doesnotexist/
mv: cannot create regular file ‘/doesnotexist/’: Not a directory

POSIX says nothing about mv behavior, so I think it's safe to say that changing the behavior from a usage message to something more usable is desired for FreeBSD usability: http://pubs.opengroup.org/onlinepubs/009604599/utilities/mv.html
Comment 1 Ed Maste freebsd_committer freebsd_triage 2015-06-25 16:33:02 UTC
What does Fedora show for the same case?  That is,
mv file1 file2 directory-that-does-not-exist/
Comment 2 Andriy Gapon freebsd_committer freebsd_triage 2015-06-25 20:30:42 UTC
(In reply to Ed Maste from comment #1)
CentOS 7.1 reports:
mv: target ‘/tmp/foo-bar’ is not a directory
Comment 3 Enji Cooper freebsd_committer freebsd_triage 2015-06-26 00:36:53 UTC
[ngie@wkstn-lnx-ngie ~]$ touch file1 file2
[ngie@wkstn-lnx-ngie ~]$ mv file1 file2 directory-that-does-not-exist/
mv: target ‘directory-that-does-not-exist/’ is not a directory
[ngie@wkstn-lnx-ngie ~]$ cat /etc/redhat-release 
Fedora release 20 (Heisenbug)
Comment 4 Jilles Tjoelker freebsd_committer freebsd_triage 2015-06-26 16:03:02 UTC
This was already fixed for cp a while ago. It should be easy to port over.
Comment 5 commit-hook freebsd_committer freebsd_triage 2015-06-28 21:36:59 UTC
A commit references this bug:

Author: jilles
Date: Sun Jun 28 21:36:01 UTC 2015
New revision: 284916
URL: https://svnweb.freebsd.org/changeset/base/284916

Log:
  mv: Improve message when moving two or more files to non-directory.

  The message text is from cp, which has had a nicer message for this since
  2007 (PR bin/50656).

  As with cp, the exit status changes from 64 to 1.

  PR:		201083
  MFC after:	1 week

Changes:
  head/bin/mv/mv.c
Comment 6 Jilles Tjoelker freebsd_committer freebsd_triage 2015-06-28 21:37:39 UTC
Fixed in head.
Comment 7 commit-hook freebsd_committer freebsd_triage 2015-08-22 21:36:33 UTC
A commit references this bug:

Author: jilles
Date: Sat Aug 22 21:35:36 UTC 2015
New revision: 287027
URL: https://svnweb.freebsd.org/changeset/base/287027

Log:
  MFC r284916: mv: Improve message when moving two or more files to
  non-directory.

  The message text is from cp, which has had a nicer message for this since
  2007 (PR bin/50656).

  As with cp, the exit status changes from 64 to 1.

  PR:		201083

Changes:
_U  stable/10/
  stable/10/bin/mv/mv.c