Skip to content

nshlib/nsh_fscmds: Display modification time in ls -l output#3571

Open
Zepp-Hanzj wants to merge 1 commit into
apache:masterfrom
Zepp-Hanzj:fix/ls-long-timestamp
Open

nshlib/nsh_fscmds: Display modification time in ls -l output#3571
Zepp-Hanzj wants to merge 1 commit into
apache:masterfrom
Zepp-Hanzj:fix/ls-long-timestamp

Conversation

@Zepp-Hanzj

Copy link
Copy Markdown
Contributor

Summary

Add modification time display to ls -l long format output.

Fixes #17063

Details

The ls -l command now shows the modification time (st_mtime) in
YYYY-MM-DD HH:MM format (ISO long-iso style) between the permission
string and the file size.

Files with st_mtime == 0 (e.g., procfs, tmpfs pseudo-entries) skip
the timestamp display to avoid showing a meaningless epoch time.

Changes

  • nshlib/nsh_fscmds.c: Add #include <time.h> and timestamp display
    logic in ls_handler() after the permission details output.

Verification

Built and tested on sim:nsh configuration.

ls -l /:

 dr-xr-xr-x           0 bin/
 drwxr-xr-x 2026-06-29 11:21        4096 data/
 drwxrwxrwx           0 dev/
 dr-xr-xr-x           0 etc/

ls -l /data:

 -rw-r--r-- 2026-06-29 11:20         152 .version
 -rw-r--r-- 2026-06-29 11:20        1883 .config.backup
 drwxr-xr-x 2026-06-29 11:21        4096 binfmt/
 -rw-r--r-- 2026-06-01 08:56        3107 NOTICE
 -rw-r--r-- 2026-06-05 15:33           6 hello.txt

ls -l /proc (procfs, st_mtime == 0, timestamp correctly skipped):

 dr--r--r--           0 0/
 dr--r--r--           0 1/
 -r--r--r--           0 cpuinfo

ls -l /dev (pseudo-devices, st_mtime set to boot time):

 crw-rw-rw- 2026-06-29 11:21           0 console
 crw-rw-rw-           0 rtc0

rtc0 has st_mtime == 0 so the timestamp is correctly omitted.

Signed-off-by: hanzhijian hanzhijian@zepp.com

Comment thread nshlib/nsh_fscmds.c Outdated

/* Display modification time */

if (buf.st_mtime != 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need move just before file name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Moved the timestamp display to just before the filename, after the size output.

Comment thread nshlib/nsh_fscmds.c
}

#ifdef CONFIG_SCHED_USER_IDENTITY
if ((lsflags & LSFLAGS_UID_GID) != 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove LSFLAGS_UID_GID, but check LSFLAGS_LONG

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Now checking only LSFLAGS_LONG: if ((lsflags & LSFLAGS_LONG) != 0 && buf.st_mtime != 0)

acassis
acassis previously approved these changes Jun 29, 2026
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 <hanzhijian@zepp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants