7

Windirstat/ Kdirstat/ Disk Inventory X has been nothing short of revolutionary in file managment. Why is there no text-only command line equivalent? I'd need it for SSH administration of my file servers.

We have all the building blocks: du, tree etc.

Is there one? Why not? Can someone please write one? :)

EDIT: du does ALMOST what I want. What I want is something that sorts each subdirectory by size (rather than full path) and indents so that it's easier to avoid double-counting. du would give me this:

cd a
du . -h

1G  b
2G  c
1K  c/d
1K  c/e
2G  c/f

It's not immediately obvious that c and c/f are overlapping. What I want is this:

cd a
dir_stats .

1G  b
2G  c
    |
    +---- 2G  f
    |
    +---- 1K  d
    |
    +---- 1K  e

in which it is clear that the 2G from f is because of the 2G from c. I can find all the info not related to c more easily (i.e. by just scanning the first column).

Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
  • Could you round out your question a bit better? It would seem that du does everything that you might need to perform the same functionality. Kdirstat and it's kin are actually based off of du functionality, just providing a graphical interface. Are you just looking for ways to tweak the reported information? – bubba Mar 29 '13 at 20:24
  • I've attempted to clarify. I hpe this makes some sense – Sridhar Sarnobat Mar 29 '13 at 21:45
  • 2
    Actually this is a duplicate of: http://unix.stackexchange.com/questions/45828/print-size-of-directory-content-with-tree-command-in-tree-1-5 – Sridhar Sarnobat Mar 29 '13 at 21:52
  • 3 years on and I actually feel this isn't necessary (but thank you for the answers). I religiously use `du` as it is now and can see why it's designed the way it is. – Sridhar Sarnobat Jan 06 '16 at 23:19

4 Answers4

13

I'd recommend using ncdu, which stands for NCurses Disk Usage. Basically it's a collapsible version of du, with a basic command line user interface.

One thing worth noting is that it runs a bit slower than du on large amounts of data, so I'd recommend running it in a screen or using the command line options to first scan the directory and then view the results. Note the q option, it reduces the refresh rate from 1/10th of a second to 2 seconds, recommended for SSH connections.

Viewing total root space usage:

ncdu -xq /

Generate results file and view later:

ncdu -1xqo- / | gzip > export.gz
# ...some time later:
zcat export.gz | ncdu -f-
onik
  • 1,922
  • 1
  • 18
  • 32
  • sounds interesting, I'll take a look. – Sridhar Sarnobat May 15 '13 at 23:30
  • Yikes, a non-interactive command line tool. I've never been a fan of those (same reason I don't like pine). Is it possible to script the execution, dump the output to the terminal and return control to the prompt? – Sridhar Sarnobat May 15 '13 at 23:38
  • 2
    You can get output to the terminal with `ncdu -1xqo- /` or to a file with `ncdu -1xqo file.json`. The output is JSON and described [here](http://dev.yorhel.nl/ncdu/jsonfmt), so you could write your own output formatter with a little effort. – onik May 16 '13 at 05:52
4

You can use KDirStat (or the new QDirStat) together with the perl script that comes along with either one to collect data on your server, then copy that file to your desktop machine and view it with KDirStat / QDirStat.

See also

https://github.com/shundhammer/qdirstat/tree/master/scripts

or

https://github.com/shundhammer/kdirstat/blob/master/kdirstat/kdirstat-cache-writer

The script does not seem to be included with the KDE 4 port K4DirStat, but it can still read and write the same cache files.

-- HuHa (Stefan Hundhammer - author of the original KDirStat)

HuHa
  • 161
  • 7
  • What does the output look like? Can you post a sample? – Sridhar Sarnobat Jan 06 '16 at 23:25
  • 2
    "File" menu -> "Read Cache File" in QDirStat / KDirStat / K4DirStat will give you this screen ( you can close the bottom half with the treemap display if you are not interested in that): [(https://github.com/shundhammer/qdirstat/blob/master/screenshots/QDirStat-main-win.png](https://github.com/shundhammer/qdirstat/blob/master/screenshots/QDirStat-main-win.png) – HuHa Jan 07 '16 at 12:20
  • 1
    The cache file format itself is well-documented: [https://github.com/shundhammer/qdirstat/blob/master/doc/cache-file-format.txt](https://github.com/shundhammer/qdirstat/blob/master/doc/cache-file-format.txt); Example (unzipped, short format): [http://paste.opensuse.org/85093270](http://paste.opensuse.org/85093270); Example in long format (with option -l): [http://paste.opensuse.org/35861400](http://paste.opensuse.org/35861400) The cache file contains path, filename, own size, mtime; the other fields are calculated upon loading the file. – HuHa Jan 07 '16 at 12:30
  • 1
    Detailed instructions now available here: https://github.com/shundhammer/qdirstat/blob/master/doc/QDirStat-for-Servers.md – HuHa Feb 18 '17 at 14:03
1

As mentioned here: https://unix.stackexchange.com/questions/45828/print-size-of-directory-content-with-tree-command-in-tree-1-5

tree --du -h -L 2

is very much in the right spirit of my goal. The only problem is, I don't think it supports sorting so is not suitable for huge file system hierarchies :(

Community
  • 1
  • 1
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
0

Don't bother trying to do disk space management with ascii art visializations. Du follows Unix's elegant philosophy in all respects and so gives you sorting etc for free.

Get comfortable with du and you'll have much more power in finding disk hogs remotely

Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106