From: Pádraig Brady Date: Fri, 12 Aug 2022 13:16:14 +0000 (+0100) Subject: ls: support explicit --time=modification selection X-Git-Tag: v9.2~162 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a88b666bea3916b978373f89b5f11f3d5b7157a6;p=thirdparty%2Fcoreutils.git 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. --- diff --git a/NEWS b/NEWS index 3113d42363..eea683396f 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 35f90d4172..c034a84ddd 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 cce1c6cb1a..2960f6d38c 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 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\ diff --git a/tests/misc/ls-time.sh b/tests/misc/ls-time.sh index af41648123..33e32866ad 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") ;; *)