Author: grog
Date: Thu Nov 8 00:24:26 2012
New Revision: 242725
URL: http://svnweb.freebsd.org/changeset/base/242725
Log:
Add y flag and environment variable LS_SAMESORT to specify the same
sorting order for time and name with the -t option. IEEE Std 1003.2
(POSIX.2) mandates that the -t option sort in descending order, and
that if two files have the same timestamp, they should be sorted in
ascending order of their names. The -r flag reverses both of these
sort orders, so they're never the same. This creates significant
problems for sequentially named files stored on FAT file systems,
where it can be impossible to list them in the order in which they
were created.
Add , (comma) option to print file sizes grouped and separated by
thousands using the non-monetary separator returned by localeconv(3),
typically a comma or period.
MFC after: 14 days
Modified:
head/bin/ls/cmp.c
head/bin/ls/ls.1
head/bin/ls/ls.c
head/bin/ls/ls.h
head/bin/ls/print.c
head/bin/ls/util.c
Modified: head/bin/ls/cmp.c
==
--- head/bin/ls/cmp.c Wed Nov 7 23:50:28 2012(r242724)
+++ head/bin/ls/cmp.c Thu Nov 8 00:24:26 2012(r242725)
@@ -78,7 +78,10 @@ modcmp(const FTSENT *a, const FTSENT *b)
if (b->fts_statp->st_mtim.tv_nsec <
a->fts_statp->st_mtim.tv_nsec)
return (-1);
- return (strcoll(a->fts_name, b->fts_name));
+if (f_samesort)
+ return (strcoll(b->fts_name, a->fts_name));
+else
+ return (strcoll(a->fts_name, b->fts_name));
}
int
@@ -104,7 +107,10 @@ acccmp(const FTSENT *a, const FTSENT *b)
if (b->fts_statp->st_atim.tv_nsec <
a->fts_statp->st_atim.tv_nsec)
return (-1);
- return (strcoll(a->fts_name, b->fts_name));
+if (f_samesort)
+ return (strcoll(b->fts_name, a->fts_name));
+else
+ return (strcoll(a->fts_name, b->fts_name));
}
int
@@ -130,7 +136,10 @@ birthcmp(const FTSENT *a, const FTSENT *
if (b->fts_statp->st_birthtim.tv_nsec <
a->fts_statp->st_birthtim.tv_nsec)
return (-1);
- return (strcoll(a->fts_name, b->fts_name));
+if (f_samesort)
+ return (strcoll(b->fts_name, a->fts_name));
+else
+ return (strcoll(a->fts_name, b->fts_name));
}
int
@@ -156,7 +165,10 @@ statcmp(const FTSENT *a, const FTSENT *b
if (b->fts_statp->st_ctim.tv_nsec <
a->fts_statp->st_ctim.tv_nsec)
return (-1);
- return (strcoll(a->fts_name, b->fts_name));
+if (f_samesort)
+ return (strcoll(b->fts_name, a->fts_name));
+else
+ return (strcoll(a->fts_name, b->fts_name));
}
int
Modified: head/bin/ls/ls.1
==
--- head/bin/ls/ls.1Wed Nov 7 23:50:28 2012(r242724)
+++ head/bin/ls/ls.1Thu Nov 8 00:24:26 2012(r242725)
@@ -32,7 +32,7 @@
.\" @(#)ls.1 8.7 (Berkeley) 7/29/94
.\" $FreeBSD$
.\"
-.Dd September 28, 2011
+.Dd November 8, 2012
.Dt LS 1
.Os
.Sh NAME
@@ -40,7 +40,7 @@
.Nd list directory contents
.Sh SYNOPSIS
.Nm
-.Op Fl ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx1
+.Op Fl ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,
.Op Fl D Ar format
.Op Ar
.Sh DESCRIPTION
@@ -130,6 +130,8 @@ This option is equivalent to defining
.Ev CLICOLOR
in the environment.
(See below.)
+This functionality can be compiled out by removing the definition of
+.Ev COLORLS .
.It Fl H
Symbolic links on the command line are followed.
This option is assumed if
@@ -249,12 +251,35 @@ subsection below, except (if the long fo
the directory totals are not output when the output is in a
single column, even if multi-column output is requested.
.It Fl t
-Sort by time modified (most recently modified
-first) before sorting the operands in lexicographical
-order.
+Sort by descending time modified (most recently modified first). If two files
+have the same modification timestamp, sort their names in ascending
+lexicographical order.
+The
+.Fl r
+option reverses both of these sort orders.
+.Pp
+Note that these sort orders are contradictory: the time sequence is in
+descending order, the lexicographical sort is in ascending order.
+This behavior is mandated by
+.St -p1003.2 .
+This feature can cause problems listing files stored with sequential names on
+FAT file systems, such as from digital cameras, where it is possible to have
+more than one image with the same timestamp.
+In such a case, the photos cannot be listed in the sequence in which
+they were taken.
+To ensure the same sort order for time and for lexicographical sorting, set the
+environment variable
+.Ev LS_SAMESORT
+or use the
+.Fl y
+option.
+This causes
+.Nm
+to reverse the lexicographal sort order when sorting files with the
+same