Skip to content

nshlib: add du command support#3656

Open
Junbo-Zheng wants to merge 1 commit into
apache:masterfrom
Junbo-Zheng:nshlib
Open

nshlib: add du command support#3656
Junbo-Zheng wants to merge 1 commit into
apache:masterfrom
Junbo-Zheng:nshlib

Conversation

@Junbo-Zheng

@Junbo-Zheng Junbo-Zheng commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Add a du (disk usage) command to NSH that recursively summarizes the size of each path argument in 1K-blocks, or in human-readable form with -h. Also supports -s (summary only), -a (all files), -d N (max-depth), and -h, matching GNU du semantics.

Impact

  • Users: New du command in NSH; no existing command or behavior
    changed.
  • Build: Adds CONFIG_NSH_DISABLE_DU (default follows
    DEFAULT_SMALL) to omit the command on small builds.
  • Hardware: None -- NSH addition, board-independent.
  • Documentation: None -- usage shown via NSH help.

Testing

Built and run on sim:nsh (host Ubuntu 22.04):

cmake -B out/nuttx_sim_nsh -S nuttx -DBOARD_CONFIG=sim:nsh -GNinja
ninja -C out/nuttx_sim_nsh
./out/nuttx_sim_nsh/nuttx

-h prints one decimal via integer arithmetic, float printf:

nsh> du
397449  /data/test/elf
71993   /data/test/coredump
5       /data/test/log2
3251    /data/test/log1
472700  /data/test

nsh> du -h
388.1M  /data/test/elf
70.3M   /data/test/coredump
4.1K    /data/test/log2
3.1M    /data/test/log1
461.6M  /data/test

Host Ubuntu 22.04 du on the same directory

$ du
397456  ./elf
72000   ./coredump
8       ./log2
3252    ./log1
472720  .

$ du -h
389M  ./elf
71M   ./coredump
8.0K  ./log2
3.2M  ./log1
462M  .

@acassis

acassis commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

@Junbo-Zheng please fix:

FAILED: nuttx 
: && /tools/ccache/bin/arm-none-eabi-gcc  --specs=nosys.specs   -Wl,--print-memory-usage -Wl,--entry=__start -nostdlib -Wl,--gc-sections -Wl,--cref -Wl,-Map=nuttx.map @CMakeFiles/nuttx.rsp -o nuttx  && :
/tools/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: apps/libapps.a(nsh_fscmds.c.o): in function `du_recursive':
/github/workspace/sources/apps/nshlib/nsh_fscmds.c:1960:(.text.du_recursive+0xae): undefined reference to `nsh_getdirpath'
Memory region         Used Size  Region Size  %age Used

Add a du command to NSH that recursively summarizes the size of each
path argument in 1K-blocks, or human-readable form with -h.

Supports -s (summary only), -a (all files), -d N (max-depth), and -h,
matching GNU du semantics.

Testing:

Built and ran on sim:nsh with:
```bash
  cmake -B out/nuttx_sim_nsh -S nuttx -DBOARD_CONFIG=sim:nsh -GNinja
  ninja -C out/nuttx_sim_nsh
  ./out/nuttx_sim_nsh/nuttx

  nsh> du
  397449  /data/test/elf
  71993   /data/test/coredump
  5       /data/test/log2
  3251    /data/test/log1
  472700  /data/test

  nsh> du -h
  388.1M  /data/test/elf
  70.3M   /data/test/coredump
  4.1K    /data/test/log2
  3.1M    /data/test/log1
  461.6M  /data/test
```

Host Ubuntu22.04 du on the same directory:
```bash
  $ du
  397456  ./elf
  72000   ./coredump
  8       ./log2
  3252    ./log1
  472720  .

  $ du -h
  389M  ./elf
  71M   ./coredump
  8.0K  ./log2
  3.2M  ./log1
  462M  .
```

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.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.

2 participants