1

My cloud instance (running a web app) disk usage went up inexplicably, I suspect there is something like a storage leak there. Is there any way to the breakdown of disk usage by directory, in order to find out the directories that take up a lot of storage, so that I can investigate?

Note that in this cloud instance, I don't have GUI and have to rely on the terminal (through SSH).

The difference between this question and the linked related question is I want to find a breakdown, not just total usage of a directory.

user69715
  • 203

5 Answers5

4

You could try gt5. It lists the disk usage of the contents your current directory, or a specified directory, ordered by highest to lowest. If you see that, for example, /var/tmp is using a lot of space, you can do:

sudo gt5 /var/tmp

To see the usage of that folders contents. To see the basics of where in your system the disk use is going, try:

sudo gt5 /

To get it, simply do:

sudo apt-get install gt5
kos
  • 35,891
  • I'm on mobile, it kept forcing the capitals on me. Do not capitalize sudo. –  Dec 07 '15 at 02:58
3

Disk Usage Analyzer (AKA baobab) is great to get a quick breakdown of where the disk space is going; so I'd suggest using Disk Usage Analyzer through SSH with X forwarding.

X forwarding should be enabled both on the client and on the server in order to work; it should be enabled by default on the server, so it should be just a matter of enabling it in the current client session:

ssh -X user@host baobab 
kos
  • 35,891
1

Do du -sh * in the root directory.

kos
  • 35,891
Jay
  • 2,270
0

Other utility available in many distros (and Windows' Cygwin) for disk usage analysis in console mode is ncdu, where

ncdu -q /home/user

will show a browseable list of directories/files conveniently sorted by size. The option -q increases the refresh interval of progress reporting, speeding the gathering of directory data.

Pressing h shows the hotkeys list, and q closes the program.

Other very useful option when searching for space hogs is -x for checking only the partition where is the target directory, ignoring links that refer to other partitions:

ncdu -xq /

As always, man ncdu is your friend.

Fjor
  • 300
0

You can use the du command to print the breakdown of disk usage by directory. The du command can recursively calculate the size of directories and their contents, and the sort command can be used to sort the results by size.

Here's an example command that will print the breakdown of disk usage by directory, sorted by size:

du -h / | sort -h

This command will calculate the disk usage of the root directory (/) and all its subdirectories, and display the sizes in a human-readable format (-h). The sort -h command will sort the output by size, with the smallest directories first and the largest directories last.

You can modify the command to start from a different directory if you suspect that the storage leak is coming from a specific directory. For example, if you suspect that the leak is coming from the /var directory, you can use the following command:

du -h /var | sort -h

This will calculate the disk usage of the /var directory and its subdirectories, and display the sizes sorted by size.

Once you have identified the directories that are taking up a lot of storage, you can investigate further to determine the cause of the storage leak.