Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the disk usage of each subdirectory in Linux?

Tags:

linux

bash

I have a directory, /var/lib/docker, which contains several subdirectories:

/var/lib/docker$ sudo ls
aufs  containers  image  network  plugins  swarm  tmp  trust  volumes

I'd like to find out how big each directory is. However, using the du command as follows,

/var/lib/docker$ sudo du -csh .
15G .
15G total

I don't see the 'breakdown' for each directory. In the examples I've seen in http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/, however, it seems that I should see it. How might I obtain this overview to see which directory is taking up the most space?

like image 517
Kurt Peek Avatar asked Apr 28 '17 13:04

Kurt Peek


People also ask

How do I check disk usage per directory in Linux?

Linux command to check disk space using:df command – Shows the amount of disk space used and available on Linux file systems. du command – Display the amount of disk space used by the specified files and for each subdirectory.

How do I find the size of a directory wise in Linux?

To get the total size of a directory in Linux, you can use the du (disk-usage) command. In this article, we'll take a look at some of the most common usages of the du commands, including but not limited to du -sh , du -ch , and du --max-depth .

Which command shows a breakdown of disk usage by directory?

The du command with the options -s (–summarize) and -h (–human-readable) can be used to find out how much disk space a directory is consuming.

How do I display subdirectories in Linux?

If you name one or more directories on the command line, ls will list each one. The -R (uppercase R) option lists all subdirectories, recursively. That shows you the whole directory tree starting at the current directory (or the directories you name on the command line).


2 Answers

Use asterisk to get info for each directory, like this:

sudo du -hs *

It will output something like the below:

0       backup
0       bin
70M     boot
0       cfg
8.0K    data
0       dev
140K    docs
like image 55
AlecTMH Avatar answered Sep 24 '22 06:09

AlecTMH


ncdu is also a nice way to analyze disk usage. It allows to quickly navigate through subdirectories and identify largest directories and files.

It should be available in most distributions official repositories.

like image 40
Skippy le Grand Gourou Avatar answered Sep 20 '22 06:09

Skippy le Grand Gourou