[FEATURE] ls command doesn't show files date / timestamp
Is your feature request related to a problem? Please describe.
NuttX "ls -l" command currently doesn't show the file timestamp, although this information is stored in some filesystems supported by NuttX.
Describe the solution you'd like
Modify ls_handler() to print timestamp when it is available.
Describe alternatives you've considered
No response
Verification
- [x] I have verified before submitting the report.
@acassis from the stat struct , time_t st_atime; /* Time of last access / time_t st_mtime; / Time of last modification / time_t st_ctime; / Time of last status change */
- st_mtime should be displayed right?
Hi @Biancaa-R, yes I think normally the last modification (or creation time, if the file wasn't modified) should be displayed. Are you willing to implement and contribute it?
Hi @Biancaa-R, yes I think normally the last modification (or creation time, if the file wasn't modified) should be displayed. Are you willing to implement and contribute it?
Yes ,I am ,Ill finish it soon :)
@Biancaa-R I searched more about it and discovered that it is possible to print the other timestamps too.
On Linux and other POSIX systems: ls -l shows the modification time (st_mtime) ls -lu shows the access time (st_atime) ls -lc shows the status change time (st_ctime)
So by convention, ls -l (without options) displays st_mtime. I think "ls -l" is enough.
@Biancaa-R I searched more about it and discovered that it is possible to print the other timestamps too.
On Linux and other POSIX systems: ls -l shows the modification time (st_mtime) ls -lu shows the access time (st_atime) ls -lc shows the status change time (st_ctime)
So by convention, ls -l (without options) displays st_mtime. I think "ls -l" is enough.
Ok ,thanks a lot.
Is your feature request related to a problem? Please describe.
NuttX "ls -l" command currently doesn't show the file timestamp, although this information is stored in some filesystems supported by NuttX.
Describe the solution you'd like
Modify ls_handler() to print timestamp when it is available.
Describe alternatives you've considered
No response
Verification
* [x] I have verified before submitting the report.
@acassis I am unable to find the ls_handler when I greped the code ... But I saw mkdir implemented as fs_mkdir ,so can I add the implementation as fs_ls.c in fs/vfs ? Or do you want me to edit nshlib/nsh_fscmds.c in apps that has ls_handler ?
Im sorry for the delay I was caught up with cllg exams :/
@Biancaa-R the ls_handler is in nuttx-apps, not in nuttx repository, see:
alan@dev:~/nuttxspace/apps$ git grep ls_handler nshlib/nsh_fscmds.c: * Name: ls_handler nshlib/nsh_fscmds.c:static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR const char dirpath, nshlib/nsh_fscmds.c: ret = nsh_foreach_direntry(vtbl, "ls", newpath, ls_handler, pvarg); nshlib/nsh_fscmds.c: / Pass a null dirent to ls_handler to signify that this is a single nshlib/nsh_fscmds.c: ret = ls_handler(vtbl, fullpath, NULL, nshlib/nsh_fscmds.c: ret = nsh_foreach_direntry(vtbl, "ls", fullpath, ls_handler,
@Biancaa-R the ls_handler is in nuttx-apps, not in nuttx repository, see:
alan@dev:~/nuttxspace/apps$ git grep ls_handler nshlib/nsh_fscmds.c: * Name: ls_handler nshlib/nsh_fscmds.c:static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR const char dirpath, nshlib/nsh_fscmds.c: ret = nsh_foreach_direntry(vtbl, "ls", newpath, ls_handler, pvarg); nshlib/nsh_fscmds.c: / Pass a null dirent to ls_handler to signify that this is a single nshlib/nsh_fscmds.c: ret = ls_handler(vtbl, fullpath, NULL, nshlib/nsh_fscmds.c: ret = nsh_foreach_direntry(vtbl, "ls", fullpath, ls_handler,
perfect , understood ,thanks a lot @acassis !
@acassis I tried a implementation but it produces sketchy results .. Files that were never modified show the epoch time and somehow one shows the future .. I used st_mtime only
NuttShell (NSH) NuttX-12.11.0
nsh> ls
/:
bin/
data/
dev/
etc/
proc/
tmp/
nsh> ls -l
/:
2044-01-09 01:18 dr-xr-xr-x 0 bin/
1970-01-01 00:00 drwxrwxr-x 4096 data/
2025-12-16 18:29 drwxrwxrwx 0 dev/
1970-01-01 00:00 dr-xr-xr-x 0 etc/
1970-01-01 00:00 dr--r--r-- 0 proc/
1970-01-01 00:00 drw-rw-rw- 0 tmp/
Once I fixed the epoch issue , the others were fixed , files that are empty / never modified are mentioned as hyphens .
@Biancaa-R is it in the future because UTC / GTM ? The sim could be using the wrong date time, you can double check it running the menuconfig and deselecting the "[*] Disable date" at:
Application Configuration -> NSH Library -> Disable Individual commands
@Biancaa-R is it in the future because UTC / GTM ? The sim could be using the wrong date time, you can double check it running the menuconfig and deselecting the "[*] Disable date" at:
Application Configuration -> NSH Library -> Disable Individual commands
Oh okay thanks a lot @acassis Ill do that and get back and , should I pull a pr directly in the nuttx-apps repo?
Yes, please go ahead and open a PR, congratulations! I'm happy to see you got it done! \o/