How to check diskspace and filesize in Linux

When using Linux one often come across situation to access the disk space. You need to type specific commands to get the right information. Here I will show you two commands you can use‌ in tandem for such purpose. The du and the df.

The DF :

The df report file system disk space usage.

Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda7       38001152 33607756   2439964  94% /
none                   4        0         4   0% /sys/fs/cgroup
udev             1019404        4   1019400   1% /dev
tmpfs             205624     2644    202980   2% /run
none                5120        0      5120   0% /run/lock
none             1028112      796   1027316   1% /run/shm
none              102400       20    102380   1% /run/user
/dev/sda5       77122048 54639932  18541484  75% /mnt/Old

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda7        37G   33G  2.4G  94% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            996M  4.0K  996M   1% /dev
tmpfs           201M  2.6M  199M   2% /run
none            5.0M     0  5.0M   0% /run/lock
none           1005M  792K 1004M   1% /run/shm
none            100M   20K  100M   1% /run/user
/dev/sda5        74G   53G   18G  75% /mnt/Old

The df command gives you the disk level overview of the free space.

The DU:

The du estimate file space usage starting from that directory.

cd MyIOTProjects

172    ./ESP8266-EVB-blinkLED/firmware
8    ./ESP8266-EVB-blinkLED/user
12    ./ESP8266-EVB-blinkLED/build/user
376    ./ESP8266-EVB-blinkLED/build
568    ./ESP8266-EVB-blinkLED
28    ./IoT Demos/Tweets on MOD-LED8x8RGB
36    ./IoT Demos
264    ./pinout_diagram
68    ./arduino_style/arduino
84    ./arduino_style

#It goes quiet long

172K    ./ESP8266-EVB-blinkLED/firmware
8.0K    ./ESP8266-EVB-blinkLED/user
12K    ./ESP8266-EVB-blinkLED/build/user
376K    ./ESP8266-EVB-blinkLED/build
568K    ./ESP8266-EVB-blinkLED
28K    ./IoT Demos/Tweets on MOD-LED8x8RGB
36K    ./IoT Demos
264K    ./pinout_diagram
68K    ./arduino_style/arduino
84K    ./arduino_style

$ du --max-depth=1 -h
568K    ./ESP8266-EVB-blinkLED
36K    ./IoT Demos
264K    ./pinout_diagram
84K    ./arduino_style
16K    ./Arduino IDE
12M    ./IoT Firmware
652K    ./esphttpd
3.7M    ./HARDWARE
21M    ./.git
37M    .

Here the max-depth is the level at which it prints the information.

For more information, man du and man df.

One thought on “How to check diskspace and filesize in Linux

  • March 21, 2017 at 10:13 pm

    There is a great utility called `ncdu` that makes it very easy to see where your disk space is being used.
    Install with your favorite package manager and simply run.


Leave a Reply

Your email address will not be published. Required fields are marked *