How to get disk usage from command line?

268,833

Solution 1

By using the df command.

Here's an example output:

$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1            303537496  27537816 260580948  10% /
none                    950788       252    950536   1% /dev
none                    959516       232    959284   1% /dev/shm
none                    959516       388    959128   1% /var/run
none                    959516         0    959516   0% /var/lock

Also take a look at its manpage.

Solution 2

ncdu

Works well from the command line. It's ncurses-based and interactive.
You can install it with sudo apt-get install ncdu.

enter image description here

Alternatives

  • Top ten: du -shx * | sort -rh | head -10
  • If you want more fine grained disk usage, you should take a look at the answers here.
Share:
268,833

Related videos on Youtube

Olivier Lalonde
Author by

Olivier Lalonde

Updated on September 17, 2022

Comments

  • Olivier Lalonde
    Olivier Lalonde over 1 year

    How can I get the current disk usage (in %) of my hard drive from the command line?

    • Ehtesh Choudhury
      Ehtesh Choudhury almost 11 years
      Now I wonder if there's some commandline equivalent of kdirstat or baobab.
    • belacqua
      belacqua almost 10 years
  • Oli
    Oli over 13 years
    df -m will show things in megabytes, df -h will show you in the largest possible unit.
  • Peter T.
    Peter T. about 7 years
    Install this via sudo apt install ncdu
  • G Trawo
    G Trawo over 5 years
    I liked the alternatives. You have to be in the directory you are looking for the large files. But I found it easy to spot the culprit this way without having to install anything.
  • Michael Plautz
    Michael Plautz over 5 years
    du -shx * | sort -rh | head -10 is a lifesaver! Especially great if you are on a small test server, you have run out of space, and do not already have a fancy utility installed to fix your problems.
  • Marco C.
    Marco C. over 4 years
    on CentOS sudo yum install ncdu
  • dvhirst
    dvhirst over 3 years
    The Top ten item above is very helpful, however, it omits hidden directories. Is there an easy way to include them?