Index | Thread | Search

From:
Crystal Kolipe <kolipe.c@exoticsilicon.com>
Subject:
Re: mtime format in ls -l
To:
Jan Stary <hans@stare.cz>
Cc:
tech@openbsd.org
Date:
Fri, 16 Jan 2026 12:38:40 +0000

Download raw body.

Thread
On Fri, Jan 16, 2026 at 12:24:37PM +0100, Jan Stary wrote:
> The long format of ls -l is documented as follows:
> 
>      If the -g, -l, or -n options are given, the following information is
>      displayed for each file: mode, number of links, owner (though not for
>      -g), group, size in bytes, time of last modification (???mmm dd HH:MM???),
>      and the pathname.
> 
> The mtime format only seems to be 'mmm dd HH:MM', as in 'Sep 15 13:08',
> for files with mtime less than six months ago. For older files, it becomes
> 'mmm dd  yyyy', as in 'Feb 11  2025'.

The year field is not guaranteed to be limited to four characters.

If you create a file with year > 9999, then the field expands to the right.

If you create a file with year < 0, then the field can be prefixed with a
minus sign.

If you create a file with -1000 < year < 0, then the field is padded to THREE
digits with a leading minus sign.

Although /usr/bin/touch will not allow the user to create such timestamps, it
is trivial my other means, including extracting files with such wild
timestamps from archives, etc.

Since the details from the manual page could be used by people writing scripts
that parse the output of 'ls -l', it should not imply that the output strictly
conforms to 'mmm dd  yyyy' without further qualification.

> --- ls.1.orig	Fri Jan 16 12:09:57 2026
> +++ ls.1	Fri Jan 16 12:20:54 2026
> @@ -282,7 +282,12 @@ owner (though not for
>  group,
>  size in bytes,
>  time of last modification
> -.Pq Dq mmm dd HH:MM ,
> +.Po
> +.Dq mmm dd HH:MM
> +for files last modified within the last six months,
> +.Dq "mmm dd  yyyy"
> +otherwise
> +.Pc
>  and the pathname.
>  In addition, for each directory whose contents are displayed, the first
>  line displayed is the total number of blocks used by the files in the
>