当前位置: 首页 > news >正文

Install ncdu Disk Usage Analyzer on Linux

When the disk is filling up and you need to know what’s eating it,ncduis the fastest tool to point at the problem directory. It’s an ncurses disk usage analyzer: it scans a tree once, caches the results in memory, and then lets you browse every subdirectory sorted by size. No flags to remember, no GUI required, and it works equally well over an SSH session to a remote server.

This guide installsncduon Rocky Linux 10 and Ubuntu 24.04, then walks through the scan, navigation, export-import workflow, and a few flags that make it useful for automated disk audits over SSH.

TestedApril 2026on Rocky Linux 10.1 with ncdu 1.22 from EPEL 10

Step 1: Install ncdu

On Rocky Linux 10, AlmaLinux 10, and RHEL 10,ncdulives in EPEL. Enable the CRB repo first (EPEL packages sometimes depend on CRB) and install:

sudo /usr/bin/crb enable sudo dnf install -y epel-release sudo dnf install -y ncdu

Copy

Debian 13 and Ubuntu 24.04 ship it inmain, so a single apt call is enough:

sudo apt update sudo apt install -y ncdu

Copy

Confirm the install and version:

ncdu --version

Copy

On a current Rocky 10 minimal image this reports:

ncdu 1.22

Copy

ncdu 1.2x has the rewritten scanner that’s several times faster than the 1.x series that still ships on some older RHEL derivatives. If you get something below 1.10, upgrade before relying on it for large filesystem scans.

Step 2: Interactive scan of a directory

Runncduagainst the directory you want to analyze. The most common target is the whole root filesystem, but because descending into/proc,/sys,/dev, and mounted filesystems wastes time, use-xto stay on a single filesystem and--exclude-kernfsto skip pseudo filesystems:

sudo ncdu -x --exclude-kernfs /

Copy

The scanner runs for a few seconds to a few minutes depending on the filesystem size, then drops you into the interactive browser. The top line shows the absolute path, and the column below lists subdirectories sorted biggest-first with their usage as a percentage of the parent and a bar graph.

Step 3: Key bindings you’ll actually use

ncdu is entirely keyboard-driven. Five bindings cover 95% of real usage:

  • arrow keys / j k: move up and down the list
  • Enter / right arrow / l: descend into a directory
  • left arrow / h: go back up
  • d: delete the selected file or directory (with confirm)
  • g: toggle between bytes, graph, and percentage
  • q: quit

Two more worth knowing: press?anytime for the full help screen, andn/s/Ctoggle sort order by name, size, and item count. Pressingion a highlighted item opens a details pane with owner, permissions, and mtime.

Step 4: Non-interactive scans for scripting

ncdu can export a full scan to a JSON file using-o. This is perfect for automation: run the scan on a server, copy the JSON to your laptop, and open it there for analysis without touching the remote box again. The-qflag tells ncdu to run in quiet (non-interactive) mode:

ncdu -q -o /tmp/ncdu.json /usr

Copy

The output file is plain text JSON so you can inspect it withhead:

ls -la /tmp/ncdu.json head -c 200 /tmp/ncdu.json

Copy

On a stock Rocky 10 VM scanning/usr, the JSON file comes in at around 2.3 MB and starts like this:

-rw-r--r--. 1 rocky rocky 2291160 Apr 12 03:04 /tmp/ncdu.json [1,2,{"progname":"ncdu","progver":"1.22","timestamp":1775952272}, [{"name":"/usr","asize":144,"dev":64516}, [{"name":"bin","asize":24576,"dsize":40960}, {"name

Copy

Open the exported scan in another ncdu session with-f:

ncdu -f /tmp/ncdu.json

Copy

Navigation is identical to a fresh scan, but nothing touches the disk because ncdu reads from the JSON cache. This is also the way to audit a remote server without keeping an SSH session open for the duration of a slow scan: runncdu -q -o scan.json /on the server,scpthe file down, and browse it at your leisure.

Step 5: Scanning excluded paths

Skip noisy directories with--exclude. Multiple exclusions can be chained, and-X exclude.txtreads a list from a file:

sudo ncdu -x --exclude-kernfs \ --exclude /var/cache \ --exclude /var/lib/docker \ --exclude /home/*/.cache \ /

Copy

This is particularly useful when you already know Docker overlay layers or cache directories are the big consumers and you want a view of the “real” user data underneath.

Step 6: Deleting from inside ncdu

When you find a 10 GB log file you no longer need, pressdon it. ncdu asks for confirmation and then actually removes the file. The totals update immediately so you can see the reclaimed space reflected in the parent directories. This is the feature that turns ncdu from a passive analyzer into a cleanup tool.

For safety when you’re working on production, run with-r(read-only) so accidental key presses can’t delete anything:

sudo ncdu -r /var

Copy

Related tools

ncdu is the right tool when you want an interactive view of disk usage. For non-interactive one-liners (e.g., “top 10 directories by size”), the classicdu -sh */ | sort -rh | headstill works. For filesystem-level capacity and block usage on BtrFS, usebtrfs filesystem usage; for LVM thin pools,lvs. And if you just want to check that/tmpisn’t consuming disk because it’s not on its own filesystem, see our mount /tmp as tmpfs or separate partition guide.

For a broader post-install toolkit on Rocky 10, see our post-install tips guide. For interactive process monitoring see our sshfs tutorial for mounting remote filesystems you can then scan locally. And if you’re analyzing a filesystem on a disk image that isn’t mounted, the qemu-img conversion guide shows how to flip the image into a formatguestmountcan open. For hardware-level checks to pair with disk analysis, the dmidecode reference covers the other half of the audit.

http://www.jsqmd.com/news/793298/

相关文章:

  • ARM710a处理器架构与性能优化实战解析
  • 【C#】 HTTP 请求通讯实现指南
  • MCP TypeScript SDK 服务说明文档
  • STM32——OLED显示字符串
  • 量子自旋冰的Dirac弦约束与蒙特卡洛模拟研究
  • 告别配置烦恼:用CMake管理你的Qt + Eigen项目(附完整CMakeLists.txt)
  • 机器学习在非洲公共卫生疾病预测中的实战应用与技术解析
  • Java+YOLO+TensorRT 8.6:GPU 加速推理实战,延迟压至 12ms 以内
  • 基于Langchain-Chatchat构建私有化RAG知识库问答系统实战指南
  • AI代码助手性能基准测试:从原理到实践的科学评估方法
  • 封装工具类,JwtUtils令牌工具类
  • 【没事学点啥】TurboBlog轻量级个人博客项目——Turbo Blog 项目学习与上线指南
  • HQChart使用教程105-K线图,分时图如何对接AI进行数据分析
  • 基于ESP32-S3与CAN总线的开源机械臂控制器设计
  • 抖音下载器终极指南:三步轻松保存无水印视频和音乐
  • 3分钟破解百度网盘限速:直链生成工具终极指南
  • 基于Kubernetes部署Dify AI开发平台:从Docker Compose到生产级K8s方案全解析
  • 开源仿生夹爪crawdad-openclaw:从3D打印到智能抓取的完整实践指南
  • 如何快速提取Unity游戏资源?AssetStudio终极使用指南
  • 物流分拣系统:C# + YOLOv12实现快递面单信息提取与包裹体积测量
  • 【VUE专题】2. 零基础-ElementUI前端组件安装使用保姆级教程
  • 微信聊天记录永久保存与深度分析:你的数字记忆守护者
  • 第五篇:Spring事务管理——@Transactional的底层实现与失效场景
  • 软考高项选老师:这6句常见话术,听懂了你就不被割
  • Cursor AI用量监控插件:实时掌控成本,告别超支惊喜
  • 二手电车处处是坑,坐实快消品的名号,买电车只应买低价车
  • 3DGS火出圈:未来十年AI不只读写,更要看、建、做
  • 在内容生成场景中借助 Taotoken 灵活调用不同风格大模型
  • Claude Code装上“眼睛“:Browserbase Skills让AI能浏览网页
  • AI在辅助生殖中的应用:胚胎评估与妊娠预测的技术解析