[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#31038: mv copies in ls -r order
From: |
Eric Blake |
Subject: |
bug#31038: mv copies in ls -r order |
Date: |
Tue, 3 Apr 2018 09:18:46 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 |
tag 31038 notabug
thanks
On 04/03/2018 02:52 AM, 積丹尼 Dan Jacobson wrote:
> $ mv -v dir1/* dir2
> reveals that mv works backwards,
> copying in ls -r order.
Not quite true. It copies the arguments in the order given on the
command line (the * glob expands to a sorted list according to the
current locale's sorting rules) into the directory specified as the
final argument; this is NOT the same as 'ls -r' which lists ALL
arguments in a reverse-sorted lists.
For example:
$ mkdir dir1 dir2
$ touch dir1/a dir1/b
$ echo ls -r dira1/* dir2
ls -r dir1/a dir1/b dir2
$ ls -r dira1/* dir2
dir1/b dir1/a
dir2:
(which listed both entries under dir1 first, rather than listing dir2
first - that is, the glob expanded things in sorted order, then ls -r
reversed files within the same directory to list b before a but did NOT
reverse directories themselves).
$ mv -v dir1/* dir2
'dir1/a' -> 'dir2/a'
'dir1/b' -> 'dir2/b'
Here, mv processed all arguments in the order they were given (a before
b), which is different from what you claim as the 'ls -r' behavior (b
before a, even when the command line listed a before b).
> Well OK, but why is that order better than the order of the arguments it
> was given?
Because treating the final argument as the destination directory is how
it's been done for 40+ years, and so it was standardized that way.
Changing it now would break users. If you don't like it, use:
mv -v --target-directory dir2 dir1/*
This is not a bug, so I'm marking it as such in the database.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature