Cleaning up Disk Space on a Linux Machine from the Command Line

Tyler Hawkins
Level Up Coding
Published in
4 min readNov 23, 2020

--

Photo by Michael Dziedzic on Unsplash

I still run an EC2 instance on AWS that I configured years ago to host some of my side projects. It’s using a Linux AMI (Amazon machine image) that is woefully out of date and also wonderfully under-performant when traffic on my site is heavy.

Recently my EBS (elastic block store) volume that I have attached to my EC2 instance became full. Not wanting to shell out a trivial amount of cash to upgrade the size of my EC2 instance or EBS volume, I began exploring how I could remove some unnecessary files on my machine that were taking up space.

I’m by no means an expert in Linux. Hence, I probably googled 20 different things searching for solutions that could help me. Stack Overflow, blog posts, and help forums came to my rescue.

Now I’m paying it forward and sharing some commands that helped me.

Note: These commands work for Ubuntu/Debian Linux distributions. Mileage may vary for other flavors of Linux.

Checking disk usage and free disk space

To check your machine’s disk usage and see how much free space is left, you can run the following command in your terminal:

df -h

--

--