This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch releases/13.0
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/releases/13.0 by this push:
new 81a1539d4 nshlib/nsh_fscmds: Display modification time in ls -l output
81a1539d4 is described below
commit 81a1539d4b46236026dcc52f6be185a981c920ce
Author: hanzhijian <[email protected]>
AuthorDate: Mon Jun 29 19:21:51 2026 +0800
nshlib/nsh_fscmds: Display modification time in ls -l output
Fixes #17063
Add modification time display to ls -l long format output.
The timestamp is shown as 'YYYY-MM-DD HH:MM' between the permission
string and the file size, following the ISO long-iso format.
Files with st_mtime == 0 (e.g., procfs, tmpfs pseudo-entries) skip
the timestamp display to avoid showing a meaningless epoch time.
Signed-off-by: hanzhijian <[email protected]>
---
nshlib/nsh_fscmds.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c
index 797048f6c..952556ce1 100644
--- a/nshlib/nsh_fscmds.c
+++ b/nshlib/nsh_fscmds.c
@@ -37,6 +37,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <time.h>
#include <string.h>
#include <fcntl.h>
#include <dirent.h>
@@ -599,6 +600,19 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR
const char *dirpath,
nsh_output(vtbl, "%12" PRIdOFF, buf.st_size);
}
}
+
+ /* Display modification time in long format */
+
+ if ((lsflags & LSFLAGS_LONG) != 0 && buf.st_mtime != 0)
+ {
+ struct tm tm;
+ char timebuf[20];
+ time_t mtime = (time_t)buf.st_mtime;
+
+ gmtime_r(&mtime, &tm);
+ strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M", &tm);
+ nsh_output(vtbl, " %s", timebuf);
+ }
}
/* Then provide the filename that is common to normal and verbose output */