GNU bug report logs - #71803
ls --time=mtime is sorting by name instead of mtime

Previous Next

Package: coreutils;

Reported by: Dave <dmisc2 <at> gmail.com>

Date: Thu, 27 Jun 2024 15:21:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #10 received at 71803-done <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Dave <dmisc2 <at> gmail.com>, 71803-done <at> debbugs.gnu.org
Subject: Re: bug#71803: ls --time=mtime is sorting by name instead of mtime
Date: Thu, 27 Jun 2024 18:51:13 +0100
[Message part 1 (text/plain, inline)]
On 27/06/2024 16:05, Dave wrote:
> The ls command without the -l option and with the --time=mtime option,
> is incorrectly sorting by the name rather than by the modification
> time.
> 
> ls               # sorts by name (ok)
> ls --time=mtime  # sorts by name (should sort by mtime)

> // The current statement in ls.c (lines 2383-2387)
>    sort_type = (0 <= sort_opt ? sort_opt
>                 : (format != long_format
>                    && (time_type == time_ctime || time_type == time_atime
>                        || time_type == time_btime))
>                 ? sort_time : sort_name);
> 
> // Proposed correction (untested)
>    sort_type = (0 <= sort_opt ? sort_opt
>                 : (format != long_format
>                    && (time_type == time_ctime || time_type == time_atime
>                        || time_type == time_btime || time_type == time_mtime))
>                 ? sort_time : sort_name);

Right, we should be applying this GNU extension to --time=mtime also.
I.e. sorting when not displaying time (-l not specified),
and no other sorting specific option is used.

The proposed fix wouldn't work as time_mtime is the default,
so we'd be sorting by mtime rather than name by default.

I'll apply the attached later to address this.

Marking this as done.

thanks,
Pádraig
[ls--time=mtime-sort.diff (text/x-patch, attachment)]

This bug report was last modified 324 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.