ncdu
在 Linux 上,以下是NCurses 磁盘使用工具的一些示例输出:
命令:
ncdu /boot
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
但是,它是一个人机交互程序,并且输出不可编写脚本。我想将它存储到一个变量中,那么,我怎样才能获得类似的输出du
呢?
这是我的问题的后续问题:如何ncdu
快速显示磁盘使用情况并退出?
最终用途将如下所示:
output_before="$(du /boot)"
# do a bunch of stuff here which reduces the size of /boot
output_after="$(du /boot)"
echo "Before:"
echo "$output_before"
echo ""
echo "After:"
echo "$output_after"
这是一个开始,但它没有以正确的从大到小的降序显示输出:
du --all --max-depth=1 -h /boot
我最想看到的:
--- /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
但是,可接受的最低答案如下所示:
100.2 MiB /boot/initrd.img-5.13.0-28-generic
100.2 MiB /boot/initrd.img-5.13.0-27-generic
11.2 MiB /boot/vmlinuz-5.11.0-46-generic
9.7 MiB /boot/vmlinuz-5.13.0-28-generic
9.7 MiB /boot/vmlinuz-5.13.0-27-generic
9.7 MiB /boot/vmlinuz-5.13.0-25-generic
8.0 MiB /boot/grub
5.7 MiB /boot/System.map-5.13.0-28-generic
5.7 MiB /boot/System.map-5.13.0-27-generic
5.7 MiB /boot/System.map-5.13.0-25-generic
5.6 MiB /boot/System.map-5.11.0-46-generic
252.0 KiB /boot/config-5.13.0-28-generic
252.0 KiB /boot/config-5.13.0-27-generic
252.0 KiB /boot/config-5.13.0-25-generic
252.0 KiB /boot/config-5.11.0-46-generic
184.0 KiB /boot/memtest86+_multiboot.bin
184.0 KiB /boot/memtest86+.elf
180.0 KiB /boot/memtest86+.bin
16.0 KiB /boot/lost+found
4.0 KiB /boot/efi
0.0 B /boot/initrd.img.old
0.0 B /boot/initrd.img
0.0 B /boot/vmlinuz.old
0.0 B /boot/vmlinuz