Disk Space and Partitions on Linux and UNIX-like systems

Disk Space

We can check out free disk space on a Linux system with the command:

df -h


df -k

These commands are great for checking overall disk space usage, but since we usually want to check which folder (or file) occupies the most disk space, we can run the command:

du -sh * | sort -hr

The first part of the command (left side of the pipe) will return the list of files and folders with corresponding disk usage values.

The second part (right side of the pipe) will sort the results by size (disk space usage) and will put the largest sizes on the top of the list. If you want the largest sizes on the bottom, just remove the 'r' parameter (r - reverse).

This command will list only the files and folders in the path where you are located, when running this command.

A suggestion:

Run the command, then 'cd' into the largest directory and run the command again. By doing that a few times, you will most likely find the source of your largest files and directories.


Disk Partitions

List all partitions and check their size:

sudo fdisk -l /dev/sda

Open Linux partition editor in terminal:

sudo cfdisk