如何在ncdu中排除特定目录?

67

如何在ncdu扫描中排除一个目录?

我无法在man ncdu页面找到相关信息。

执行ncdu -x /时,它会花费将近一小时的时间扫描我的/home/tmp目录。

2个回答

108

ncdu 命令具有与 du 命令相同的命令行选项,因此要排除一个目录,只需使用:

ncdu命令和du命令具有相同的命令行选项,因此要排除一个目录,只需使用:

--exclude /dir/path
例如:ncdu -x / --exclude /home/tmp 要排除多个目录:ncdu -x / --exclude /home/tmp --exclude /var/log 等等。 请注意,应避免在目录名称后添加斜杠(使用/home/tmp而不是/home/tmp/),否则它将无法实际排除该目录。

21
混淆的原因是由于 dir/(斜杠结尾)无法正常工作。 - 林果皞

18

NCDU - ncdu(NCurses Disk Usage)是“du”的基于curses的版本,提供了一种快速查看哪些目录使用了您的磁盘空间的方法。

作为扫描选项的一部分,您可以通过此公式来排除一个或多个目录,从而更加准确和节省时间:

ncdu <pathToScan> --exclude=<excludeDirA> --exclude=<excludeDirB> --exclude=<excludeDirC>

例如:

sudo ncdu / --exclude=/dev --exclude=/Applications

欲查看更多选项,请参阅ncdu扫描文档:

 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.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接