I'd like to make the ncdu
NCurses Disk Usage tool analyze a path, display the output, and exit, for scripting purposes. Normally it is a human-interactive tool, but I'd like to remove the human-interactive part of it.
If I run ncdu /boot
I can see my /boot
partition. Here is what I see:
ncdu 1.14.1 ~ Use the arrow keys to navigate, press ? for help
--- /boot ---------------------------------------------
100.2 MiB [##########] initrd.img-5.13.0-28-generic
100.2 MiB [######### ] initrd.img-5.13.0-27-generic
11.2 MiB [# ] vmlinuz-5.11.0-46-generic
9.7 MiB [ ] vmlinuz-5.13.0-28-generic
9.7 MiB [ ] vmlinuz-5.13.0-27-generic
9.7 MiB [ ] vmlinuz-5.13.0-25-generic
8.0 MiB [ ] /grub
5.7 MiB [ ] System.map-5.13.0-28-generic
5.7 MiB [ ] System.map-5.13.0-27-generic
5.7 MiB [ ] System.map-5.13.0-25-generic
5.6 MiB [ ] System.map-5.11.0-46-generic
252.0 KiB [ ] config-5.13.0-28-generic
252.0 KiB [ ] config-5.13.0-27-generic
252.0 KiB [ ] config-5.13.0-25-generic
252.0 KiB [ ] config-5.11.0-46-generic
184.0 KiB [ ] memtest86+_multiboot.bin
184.0 KiB [ ] memtest86+.elf
180.0 KiB [ ] memtest86+.bin
! 16.0 KiB [ ] /lost+found
! 4.0 KiB [ ] /efi
@ 0.0 B [ ] initrd.img.old
@ 0.0 B [ ] initrd.img
@ 0.0 B [ ] vmlinuz.old
@ 0.0 B [ ] vmlinuz
Now, how can I script this to display this output, store it into a variable for later printing, and exit?
What I'd like is something like this:
output="$(ncdu /boot)"
echo "$output"
Currently it hangs at the first line since it's waiting on human interaction I think.
Follow-on question: bash: make du
show output similar to ncdu