Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory Stats command line interface?

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).

like image 684
Sridhar Sarnobat Avatar asked Mar 29 '13 20:03

Sridhar Sarnobat


People also ask

Can you use stat on a directory?

Using stat to Report on Filesystems stat can report on the status of filesystems, as well as the status of files. The -f (filesystem) option tells stat to report on the filesystem that the file resides on. Note we can also pass a directory such as “/” to stat instead of a filename.

Which command gives statistics of the file directory?

The stat is a command which gives information about the file and filesystem. Stat command gives information such as the size of the file, access permissions and the user ID and group ID, birth time access time of the file. Stat command has another feature, by which it can also provide the file system information.


2 Answers

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-
like image 134
onik Avatar answered Oct 25 '22 02:10

onik


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)

like image 45
HuHa Avatar answered Oct 25 '22 01:10

HuHa