Subject: bug#19148: ls --inode --sort=inode

From: Eric Blake <[email-masked]>
Date: Fri, 21 Nov 2014 17:33:14 -0700

On 11/21/2014 04:57 PM, 積丹尼 Dan Jacobson wrote:
> $ man ls
>        --sort=WORD
>               sort  by  WORD instead of name: none (-U), size (-S), time (-t),
>               version (-v), extension (-X)
> 
> Perhaps add new functionality: inode (-i)

Nice idea, especially since we've already proven that 'rm' and other
tasks run faster when it first sorts by inode internally.

To _some_ extent, you can get the behavior by doing:
  ls -iU | sort -k1,1n | sed 's/^[0-9]* //'
but since ls already is wired for sorting, it has a nice appeal to do it
all from with ls.  Also, my workaround doesn't help with ls outputs
other than single file per line, and isn't entirely robust if a filename
contains newline.

However, we CANNOT treat '--sort=inode' as equivalent to '-i', because
the existing meaning of -i does NOT affect sorting (all of the other
sort options -U, -S, -t, -v, and -X DO affect sorting, and --sort is
just a long-option-y way of spelling the same), and for back-compat
reasons, we cannot change the behavior of -i.  Also, I'm very reluctant
to burn another short-option letter for 'ls'.  Besides, since both '-i'
and '-I' are already burned, and what other good mnemonic would we even
have?

I guess it would be okay to have a long option with no short-option
counterpart; it would look a bit awkward in the help text, but we could
figure something out.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org