]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: support explicit --time=modification selection
authorPádraig Brady <P@draigBrady.com>
Fri, 12 Aug 2022 13:16:14 +0000 (14:16 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 13 Aug 2022 12:48:24 +0000 (13:48 +0100)
* 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
doc/coreutils.texi
src/ls.c
tests/misc/ls-time.sh

diff --git a/NEWS b/NEWS
index 3113d42363cc0815f017a18d5804e395b004cb2e..eea683396f9de0222c8c62d1e14a3e76806427ab 100644 (file)
--- 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
index 35f90d417219c9f44a31b550b6ae56c9391de8ff..c034a84dddb50425a47da73d3a2648befbcc3eab 100644 (file)
@@ -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
index cce1c6cb1aca5f9acc981153ad4ad7cfc4d13463..2960f6d38c733410f03b5d54fe693fd3837a2ed3 100644 (file)
--- 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 timestamp 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\
index af41648123f8a72eb1a113daecc00c74f9e5c68c..33e32866adeb266bb27e71bb78c5bbbec77acce8 100755 (executable)
@@ -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") ;;
   *)