AI Hints
Home›Linux Tutorial›Links and Disk Space
Linux · Lesson 41 of 120

Disk Space: du and df

What is using my disk?.

⏱ 2 min read▶ Video at 52:23🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Sooner or later, a disk fills up. When that happens, you need two answers. How much space is left? And what's using it all? DF and DU answer those questions.

Disk Space: du and df
From the video: Disk Space: du and df
  • The disk is full
  • How much is left?
  • What's using it?

How much space is left

DF, for disk free, shows each disk, its size, how much is used, and how much is available. Dash H makes the numbers human readable, in gigabytes. We pass slash, so we only see the main disk. On your computer, the name and the numbers will be different, but the columns are the same.

Terminal
df -h /
Filesystem      Size  Used Avail Use% Mounted on
overlay         103G   40G   58G  41% /

What is using the space

DU, for disk usage, shows how much space files and folders take. Dash SH gives one human readable total for each name. Downloads is the biggest, at about three point three megabytes. Now we know where to start cleaning.

Terminal
du -sh *
12K     Documents
3.3M    Downloads
8.0K    Music
60K     Pictures
4.0K    notes.txt
12K     projects
4.0K    todo.txt
du -sh Downloads
3.3M    Downloads

Finding the biggest folders

A popular combination sorts the folders by size, so the biggest come last. DU dash SH star, then a pipe, into sort dash H. We'll learn sort properly soon. And the find command from before, with dash size, finds the biggest single files.

keyvalue
df -hspace left on each disk
du -sh *size of each item here
du -sh * | sort -hbiggest last
find -size +100Mbig single files

Summary

DF dash H shows free space, and DU dash SH shows what's using it. Next, a challenge to practise everything about files.

Key takeaways
  • df -h
  • du -sh *
  • sort -h for biggest
Next up: Practice: Files Challenge — putting it all together