如何在命令行 linux 中分析磁盘使用情况?

Jad*_*ias 114 linux disk-space du df

du并且df很好,但我不知道如何过滤它们提供的数据,就像我使用SequoiaView 一样。我想一目了然地知道哪些是最大的文件夹和最大的文件。

hei*_*991 166

您可能还想尝试NCurses Disk Usage aka ncdu

ncdu -x -q远程调用它一样使用它(例如通过ssh)或ncdu -x其他方式。

ncdu 1.6 ~ Use the arrow keys to navigate, press ? for help
    --- /home/geek -----------------------------------------------------------------
       27.6MiB  /qm test 1 rework
      312.0kiB  /sidebar
       88.0kiB  /rackerhacker-MySQLTuner-perl-6add618
        8.0kiB  /.w3m
        4.0kiB  /.cache
    e   4.0kiB  /.ssh
      160.0kiB   ng.tar.gz
       76.0kiB   plowshare_1~svn1673-1_all.deb
        4.0kiB   .bashrc
        4.0kiB   .bash_history
        4.0kiB   .profile
        4.0kiB   .htoprc
        4.0kiB   .bash_logout
        0.0  B   .lesshst
Run Code Online (Sandbox Code Playgroud)

这也可以在 Mac OS X 下使用。

命令行的以下标志可能会有所帮助:

-q Quiet mode, doesn't update the screen 10 times a second
   while scanning, reduces network bandwidth used

-x Don't cross filesystem borders (don't descend into a
   directory which is a mounted disk)
Run Code Online (Sandbox Code Playgroud)

感谢索林·斯巴尼亚。


Jaa*_*ing 51

使用命令和选项的某种组合:

du --max-depth=1 2> /dev/null | sort -n -r | head -n20
Run Code Online (Sandbox Code Playgroud)

只查看最大的几个。如果您想经常使用它,请将其绑定到别名,例如在 bash 中添加到 ~/.bashrc

alias largest='du --max-depth=1 2> /dev/null | sort -n -r | head -n20'
Run Code Online (Sandbox Code Playgroud)

  • 您可以使用“sort -h”对具有人类可读后缀的值进行排序。 (3认同)
  • 要查看**最大的**几个,您需要在排序时使用 `-r` 选项。 (2认同)
  • @jumpnett:它重定向`标准错误`(在这种情况下进入`/dev/null`的黑洞)。 (2认同)

小智 8

我想推荐dutree,它提供了分层可视化。

您可以选择更多或更少的细节级别,并排除路径以更好地控制可视化。您还可以比较不同的路径。

在此处输入图片说明

它是用 Rust 实现的,快速而高效。

$ dutree -h
Usage: dutree [options] <path> [<path>..]

Options:
    -d, --depth [DEPTH] show directories up to depth N (def 1)
    -a, --aggr [N[KMG]] aggregate smaller than N B/KiB/MiB/GiB (def 1M)
    -s, --summary       equivalent to -da, or -d1 -a1M
    -u, --usage         report real disk usage instead of file size
    -b, --bytes         print sizes in bytes
    -f, --files-only    skip directories for a fast local overview
    -x, --exclude NAME  exclude matching files or directories
    -H, --no-hidden     exclude hidden files
    -A, --ascii         ASCII characters only, no colors
    -h, --help          show help
    -v, --version       print version number
Run Code Online (Sandbox Code Playgroud)