How to Exclude a Specific Directory in NCDU Command
How do I exclude a directory from ncdu scanning?
I can't found the information in man ncdu
page.
When doing ncdu -x /
it scanned my /home/tmp
directory for almost an hour.
Solution 1:
ncdu
has the same command line options as the du
command, so to exclude a directory simply use:
--exclude /dir/path
For example: ncdu -x / --exclude /home/tmp
To exclude multiple directories: ncdu -x / --exclude /home/tmp --exclude /var/log
etc.
Note that you should avoid a trailing slash (use /home/tmp
NOT /home/tmp/
) otherwise it will fail to actually exclude the directory.
Solution 2:
NCDU - ncdu (NCurses Disk Usage) is a curses-based version of the well-known 'du', and provides a fast way to see what directories are using your disk space.
As part of the scan options, you can be more accurate and save time by excluding directory or directories by this formula:
ncdu <pathToScan> --exclude=<excludeDirA> --exclude=<excludeDirB> --exclude=<excludeDirC>
for example:
sudo ncdu / --exclude=/dev --exclude=/Applications
For more options ,attaching ncdu scan documentation:
Scan Options
These options affect the scanning progress, and have no effect when
importing directory information from a file.
-x Do not cross filesystem boundaries, i.e. only count files and directories on the same filesystem as the
directory being scanned.
--exclude PATTERN
Exclude files that match PATTERN. The files will still be displayed by default, but are not counted
towards the disk usage statistics. This argument can be added multiple times to add more patterns.
-X FILE, --exclude-from FILE
Exclude files that match any pattern in FILE. Patterns should be separated by a newline.
--exclude-caches
Exclude directories containing CACHEDIR.TAG. The directories will still be displayed, but not their
content, and they are not counted towards the disk usage statistics. See
http://www.brynosaurus.com/cachedir/
-L, --follow-symlinks
Follow symlinks and count the size of the file they point to. As of ncdu 1.14, this option will not follow
symlinks to directories and will count each symlinked file as a unique file (i.e. unlike how hard links
are handled). This is subject to change in later versions.