如何在ncdu中排除指定目录?man手册未找到相关说明
Hey there, let's work through your ncdu problems. It's easy to overlook the exclude flags in the man page—those options can be tucked away in the details, so no worries about missing them initially!
Excluding Specific Directories in ncdu
ncdu actually has built-in options to skip directories, you just need to use the right flags:
- Single directory exclusion: Use the
--excludeflag directly in the command line. To skip/home/tmpwhile scanning the root filesystem, run:ncdu --exclude /home/tmp / - Multiple directories: Chain multiple
--excludeflags if you need to skip several paths:ncdu --exclude /home/tmp --exclude /var/large-log-files / - Exclude via a file: If you have a long list of paths to skip, create a text file (e.g.,
~/.ncdu-excludes) with one path/pattern per line, then use the-Xflag to reference it:
Example content forncdu -X ~/.ncdu-excludes /~/.ncdu-excludes:/home/tmp /var/cache /tmp
Fixing the Slow /home/tmp Scan
Your ncdu -x / command was slow because -x only restricts scanning to the current filesystem—it doesn't skip directories within that filesystem. Since /home/tmp is on the same root filesystem, ncdu still scans every file inside it.
Beyond excluding it, here are a couple extra tips:
- If
/home/tmpis full of disposable temporary files, consider cleaning it first withrm -rf /home/tmp/*(double-check you're deleting the right files before running this!) - If
/home/tmpis mounted as atmpfs(in-memory filesystem), scanning it usually doesn't give useful disk usage data—excluding it permanently via the exclude file is a smart move. - Use the
--exclude-cachesflag if/home/tmpis marked as a cache directory (it looks for aCACHEDIR.TAGfile inside), which will auto-skip it without needing to specify the path.
Just a quick note: Don't mix up -x (filesystem restriction) and -X (exclude file)—that's an easy mix-up that might have thrown you off when checking the man page!
内容的提问来源于stack exchange,提问作者Drunken M

