---
title: "A Comprehensive Guide to Ubuntu Disk Space Management"
description: "A step-by-step guide to managing Ubuntu disk space, including tips for organizing files, checking disk space usage, and troubleshooting disk issues."
canonical: "https://adamtheautomator.com/ubuntu-disk-space/"
---

# A Comprehensive Guide to Ubuntu Disk Space Management

> A step-by-step guide to managing Ubuntu disk space, including tips for organizing files, checking disk space usage, and troubleshooting disk issues.

Source: https://adamtheautomator.com/ubuntu-disk-space/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![A Comprehensive Guide to Ubuntu Disk Space Management](https://adamtheautomator.com/wp-content/uploads/2023/01/ubuntu-disk-space.jpg)

# A Comprehensive Guide to Ubuntu Disk Space Management

[![](https://secure.gravatar.com/avatar/1bc5e1d52466fc3739f550c8d78be310684747bf1466a98d698320627ea243e2?s=192&d=mm&r=g)Michael Nguyen Tu](https://adamtheautomator.com/author/michael-nguyen-tu/)17 January 20236 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Disk Management](/tag/disk-management/)[Linux](/tag/linux/)[Ubuntu Linux](/tag/ubuntu-linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Using the Disk App](#using-the-disk-app)
*   [Using the df Command](#using-the-df-command)
*   [Using the du Command](#using-the-du-command)
*   [Automating Disk Space Checking and File Deletion](#automating-disk-space-checking-and-file-deletion)
*   [Conclusion](#conclusion)

As an efficient and user-friendly operating system (OS), Ubuntu offers numerous tools and techniques to manage disk space and keep your system running smoothly. But without proper attention and maintenance, your Ubuntu disk space can quickly become cluttered and run out of room.

This comprehensive guide will provide many tools for managing your Ubuntu disk space, including installing and using various tools and techniques.

Read on and say goodbye to disk space anxieties with Ubuntu!

## Prerequisites

This tutorial will be a hands-on demonstration. To follow along, be sure you have an Ubuntu system. This tutorial uses Ubuntu 20.04, but other versions will work.

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

## Using the Disk App

If you are looking for a quick way to work on disk space management, GNOME-based desktop environments like Ubuntu have a default graphical partitioning tool. So long as the [gnome-disk-utility is installed](https://zoomadmin.com/HowToInstall/UbuntuPackage/gnome-disk-utility), you can access the Disks app.

The Disks app provides a visual representation of disk usage, which is intuitive for users who prefer a GUI when working with files and directories.

To see the Disks app in action with disk space management, follow these steps:

1\. Search for and open the **Disks** app, as shown below.

![ubuntu disk space - Opening the Disks App](https://adamtheautomator.com/wp-content/uploads/2023/01/image-232.png)

Opening the Disks App

2\. When the Disk app opens, click on any disk to view more detailed information, including the total size, the model, and so on.

Under the **Volumes** section, you can see a list of all partitions in your system and their associated details. The details include the device name, the partition type, the mount point, the total size, and the UUID (Universally Unique Identifier), which identifies a volume or a partition).

![Using the Disk App](https://adamtheautomator.com/wp-content/uploads/2023/01/image-233.png)

Using the Disk App

3\. Lastly, click the gear icon and choose any option you wish to perform from the context menu. Some of the actions you can take include but are not limited to the following:

<table><tbody><tr><td><strong>Option</strong></td><td><strong>Function</strong></td></tr><tr><td>Format Partition</td><td>Formatting a partition erases all its data and creates a new empty filesystem. This option is useful when you plan to reinstall your OS.</td></tr><tr><td>Edit Partition</td><td>Editing the partition allows you to change the partition’s size, format, and filesystem type without deleting any data.</td></tr><tr><td>Edit Filesystem</td><td>This option lets you change the label or name of a partition on your system. The label or name of a partition is a short, descriptive string that identifies the partition on your system.</td></tr><tr><td>Check or Repair Filesystem</td><td>This option performs a filesystem check on the volume, which can help identify and fix any problems, such as corruption or inconsistencies with the filesystem.</td></tr></tbody></table>

> 💡 _Note that filesystem checks take some time, especially if the volume is large or there are many problems with the filesystem. Moreover, filesystem repairs may cause data loss, so back up your data before proceeding._

![Accessing additional partition options](https://adamtheautomator.com/wp-content/uploads/2023/01/image-234.png)

Accessing additional partition options

## Using the `df` Command

When you mainly work in the terminal and need to check available space on your system’s disks and partitions, the disk file system (`df`) command will do the trick. The `df` command displays information about the file systems on your computer, including the device name, total size, used space, available space, and the mount point.

To see how the `df` command works, follow these steps:

1\. Open a terminal, and run the below `df` command to display a list of all file systems and their associated information in human-readable form (`-h`). You can use the `-h` option to display the sizes in “human-readable” format.

```bash
df -h
```

Below, you can see several file systems mounted on the system, as follows:

*   A main partition (`/dev/sda5`) with a total size of 20GB and 9.4GB of available space.
    
*   A _**/boot/efi**_ partition (_**/dev/sda1**_) with a total size of 511MB and 511MB of available space
    
*   Several snap packages (filesystems for software packages) are mounted at _**/snap/**_.
    
*   Many _tmpfs_ filesystems, which are memory-based filesystems used for temporary storage.
    

By default, the **`df`** command displays sizes in bytes, which is difficult to read. The `-h` option changes the display of sizes to use units such as kilobytes (**K**), megabytes (**M**), gigabytes (`G`), and terabytes (**T**). For example, the 1024000000 bytes size is displayed as 976M.

Overall, **49%** of space is used in the main partition (_**/dev/sda5**_), with 9.4GB available, as shown below. With this information, you can decide whether to delete unnecessary files to free up disk space.

![Listing all file systems](https://adamtheautomator.com/wp-content/uploads/2023/01/image-235.png)

Listing all file systems

2\. Next, run the below `watch` command to execute the `df` command at regular intervals (`5` seconds) and display updates of your disk usage in real-time.

The `watch` command, along with the `-n` option, comes in handy for monitoring changes in the system state or tracking the progress of a long-running command.

```bash
watch -n 5 df -h
```

![Monitoring disk usage updates in real-time at a certain interval](https://adamtheautomator.com/wp-content/uploads/2023/01/image-236.png)

Monitoring disk usage updates in real-time at a certain interval

3\. Lastly, run the following `df` command to list all filesystems but limit the output to specific filesystem types (`-t`), in this case, `ext4` ones.

By limiting the output to specific types, you can focus on the filesystems that are most important to you and filter out the rest. This approach can be helpful in troubleshooting a problem or if you are interested in a particular type of filesystem.

```bash
df -t ext4
```

Below, you can see the `df` command returned only one ext4 filesystem, which is the root partition (_**/dev/sda5**_).

![Listing filesystems of a specific type](https://adamtheautomator.com/wp-content/uploads/2023/01/image-237.png)

Listing filesystems of a specific type

## Using the `du` Command

Instead of getting the consumed space of an entire filesystem, you may want to determine how much space was consumed by a file or directory. How? By using the disk usage (`du`) command.

The `du` command estimates used space of a file, and a directory, down to its subdirectories.

> 💡 _The `du` command can be helpful for understanding how disk space is being used on a more granular level._

To see how the `du` command works for disk space management, follow these steps:

1\. Run the following `du` command to retrieve a summary (`-s`) of the `/tmp` directory’s usage in a human-readable format (`-h`).

```bash
du -sh /tmp
```

The output below shows that the `/tmp` directory and its subdirectories are using a total of 6.1GB of space.

In Unix-like OSes, _**/tmp**_ is a special directory used to store temporary files. Monitoring the _**/tmp**_ directory is crucial as it quickly fills up.

![Viewing a summary of a directory’s disk usage](https://adamtheautomator.com/wp-content/uploads/2023/01/image-238.png)

Viewing a summary of a directory’s disk usage

2\. Next, run the below `ls` command to list the files the `/tmp` contains in a long format (`-l`).

The long list format includes the directory’s permissions, owner, size, and modification time for each file. With this information, you can easily identify large files you may need to delete or trim down in size.

```bash
ls -l /tmp
```

In the output below, you can see that the largest file in the _**/tmp**_ directory is the _**test2.img**_ file, which you can delete if it is no longer needed.

![Listing files in the /tmp directory](https://adamtheautomator.com/wp-content/uploads/2023/01/image-239.png)

Listing files in the _/tmp_ directory

3\. Now, run the following `rm` command, which does not produce output, but [delete](https://adamtheautomator.com/ubuntu-to-delete-file/)s the specified large file (`test2.img`) to free up space in your system.

Related:[Learn the Many Ways In Ubuntu to Delete Files](https://adamtheautomator.com/ubuntu-to-delete-file/)

```bash
sudo rm -f test2.img
```

## Automating Disk Space Checking and File Deletion

Monitoring directories you do not want to be inflating helps keep your system at its peak. Why? Running out of disk space causes problems for programs that need to write temporary files.

But manually checking your disk space becomes a tedious task in the long run. So why not automate the task with a script?

In this example, you will create a script to check your disk space and delete unnecessary files automatically.

Related:[Your One and Only Linux Shell Scripting Tutorial](https://adamtheautomator.com/linux-shell-scripting-tutorial/)

1\. Create a Bash script file with your preferred editor and name it as you like, but this tutorial’s choice is _temp\_file\_terminator.sh._

2\. Next, populate the code below to the _temp\_file\_terminator.sh_ file, save the changes and close the file.

The code below checks the current size of the _`/tmp`_ directory. If the size is larger than the maximum size declared, the code runs a command to delete all files in the `/tmp` directory. Otherwise, a message prints on the console without deleting a single file.

```bash
#!/bin/bash

# Set a maximum size for the /tmp directory
MAX_SIZE=2097152

# Check the current size of the /tmp directory
CURRENT_SIZE=$(du -sk /tmp | awk '{print $1}')

# If the /tmp directory is larger than the maximum size, delete some files
if [ "$CURRENT_SIZE" -gt "$MAX_SIZE" ]
then
  echo "The /tmp directory is larger than the maximum size of 2GB. Deleting files..."

  # Find all files in /tmp that are older than three days and delete them
  find /tmp -type f -mtime +3 -delete

  # Check the size of the /tmp directory again
  CURRENT_SIZE=$(du -sk /tmp | awk '{print $1}')

  # If the /tmp directory is still larger than the maximum size, delete all files
  if [ "$CURRENT_SIZE" -gt "$MAX_SIZE" ]
  then
    rm -rf /tmp/*
    echo "All files in /tmp have been deleted."
  else
    echo "Files in /tmp have been deleted. The /tmp directory is now below the maximum size of 2GB."
  fi
else
  echo "The /tmp directory is not large enough to trigger file deletion. No files have been deleted."
fi
```

3\. Finally, run the below `bash` command to execute your script (`temp_file_terminator.sh`) from the working directory (`./`).

```bash
sudo bash ./temp_file_terminator.sh
```

Depending on the size of the _/tmp_ directory, the script will either delete files or print a message indicating no files were deleted.

![Running the Bash script to automate checking disk space and deleting files](https://adamtheautomator.com/wp-content/uploads/2023/01/image-240.png)

Running the Bash script to automate checking disk space and deleting files

## Conclusion

Managing disk space in Ubuntu is an essential skill for any Linux administrator. With the right tools and techniques, you can keep your system running smoothly with plenty of free Ubuntu disk space.

And in this tutorial, you have learned many ways to view and manage disk space from the command line and via GUI (Disks app).

Now, why not put these tools into practice and take the next step by [mastering Amazon EFS file system objects](https://docs.aws.amazon.com/efs/latest/ug/metered-sizes.html)?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-disk-space%2F&text=A%20Comprehensive%20Guide%20to%20Ubuntu%20Disk%20Space%20Management)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-disk-space%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-disk-space%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2024/03/openldap-4.jpg)

### [How to Install and Configure an OpenLDAP Ubuntu Server](/openldap/)

Unlock the power of OpenLDAP on Ubuntu for centralized user authentication, seamless access control management, and enhanced directory services!

![](https://adamtheautomator.com/wp-content/uploads/2023/08/install-go-on-ubuntu-1.jpg)

### [How to Install GO on Ubuntu Linux](/install-go-on-ubuntu/)

Learn the ins-and-outs of how to install GO Ubuntu Linux and see how you can take advantage of this popular programming language!

![](https://adamtheautomator.com/wp-content/uploads/2023/07/update-the-kernel-in-ubuntu.jpg)

### [Learn how to Update the Kernel In Ubuntu Linux Safely](/update-the-kernel-in-ubuntu/)

In this ATA Learning tutorial learn the ins-and-outs to update the kernel in Ubuntu Linux safely through several different methods!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
