nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

[FEATURE] ls command doesn't show files date / timestamp

Open acassis opened this issue 3 months ago • 8 comments

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 avatar Sep 23 '25 19:09 acassis

@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?

Biancaa-R avatar Oct 28 '25 10:10 Biancaa-R

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?

acassis avatar Oct 28 '25 13:10 acassis

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 avatar Oct 28 '25 15:10 Biancaa-R

@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.

acassis avatar Oct 28 '25 15:10 acassis

@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.

Biancaa-R avatar Oct 28 '25 16:10 Biancaa-R

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 ?

Image

Im sorry for the delay I was caught up with cllg exams :/

Biancaa-R avatar Dec 08 '25 12:12 Biancaa-R

@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,

acassis avatar Dec 10 '25 11:12 acassis

@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 !

Biancaa-R avatar Dec 10 '25 11:12 Biancaa-R

@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 .

Image

Biancaa-R avatar Dec 16 '25 18:12 Biancaa-R

@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

acassis avatar Dec 16 '25 19:12 acassis

@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?

Biancaa-R avatar Dec 16 '25 19:12 Biancaa-R

Yes, please go ahead and open a PR, congratulations! I'm happy to see you got it done! \o/

acassis avatar Dec 16 '25 19:12 acassis