The attached adds support for explicitly specifying --time=mtime.
I'm not sure about adding this, but it does give symmetry to the
description of the --time arguments.  Also it would allow
overriding a previously selected timestamp selection in an alias etc.

cheers,
Pádraig
From 3e31830cbf402f0aaa503fab413b7b0fc4d16e6e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Fri, 12 Aug 2022 14:16:14 +0100
Subject: [PATCH] ls: support explicit --time=modification selection

* src/ls.c [time_args]: Add support for explicit
'mtime' or 'modification' arguments to --time.
* tests/misc/ls-time.sh: Add explicit --time=mtime usage.
* doc/coreutils.texi (ls invocation): Describe --time=mtime.
* NEWS: Mention the new feature.
---
 NEWS                  |  3 +++
 doc/coreutils.texi    | 11 +++++++++++
 src/ls.c              |  5 ++++-
 tests/misc/ls-time.sh |  2 +-
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 3113d4236..eea683396 100644
--- a/NEWS
+++ b/NEWS
@@ -36,6 +36,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   factor now accepts the --exponents (-h) option to print factors
   in the form p^e, rather than repeating the prime p, e times.
 
+  ls now supports the --time=modification option, to explicitly
+  select the default mtime timestamp for display and sorting.
+
 ** Improvements
 
   date --debug now diagnoses if multiple --date or --set options are
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 35f90d417..c034a84dd 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -8026,6 +8026,17 @@ When sorting by time or when not using long format,
 sort according to the atime.
 @xref{File timestamps}.
 
+@item --time=mtime
+@itemx --time=modification
+@opindex --time
+@opindex data modification time@r{, printing or sorting files by}
+@opindex mtime@r{, printing or sorting files by}
+This is the default timestamp display and sorting mode.
+In long format, print the last data modification timestamp (the mtime).
+When sorting by time or when not using long format,
+sort according to the mtime.
+@xref{File timestamps}.
+
 @item --time=birth
 @itemx --time=creation
 @opindex --time
diff --git a/src/ls.c b/src/ls.c
index cce1c6cb1..5052ddd7d 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -924,6 +924,7 @@ static char const *const time_args[] =
 {
   "atime", "access", "use",
   "ctime", "status",
+  "mtime", "modification",
   "birth", "creation",
   NULL
 };
@@ -931,6 +932,7 @@ static enum time_type const time_types[] =
 {
   time_atime, time_atime, time_atime,
   time_ctime, time_ctime,
+  time_mtime, time_mtime,
   time_btime, time_btime,
 };
 ARGMATCH_VERIFY (time_args, time_types);
@@ -5555,9 +5557,10 @@ Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.\n\
 \n\
 "), stdout);
       fputs (_("\
-      --time=WORD            change the default of using modification times;\n\
+      --time=WORD            select which timestamps used to display or sort;\n\
                                access time (-u): atime, access, use;\n\
                                metadata change time (-c): ctime, status;\n\
+                               modified time (default): mtime, modification;\n\
                                birth time: birth, creation;\n\
                              with -l, WORD determines which time to show;\n\
                              with --sort=time, sort by WORD (newest first)\n\
diff --git a/tests/misc/ls-time.sh b/tests/misc/ls-time.sh
index af4164812..33e32866a 100755
--- a/tests/misc/ls-time.sh
+++ b/tests/misc/ls-time.sh
@@ -58,7 +58,7 @@ sleep 2
 ln c d || framework_failure_
 
 # Before we go any further, verify that touch's -m option works.
-set -- $(ls --full -l a)
+set -- $(ls --full -l --time=mtime a)
 case "$*" in
   *" $t3:00.000000000 +0000 a") ;;
   *)
-- 
2.26.2

Reply via email to