commands.page Website Logo

  • Home
  • Categories
  • Search

How to Get Available Storage Space on the Terminal in Ubuntu

This is an article about how to check and manage your available storage space directly from the terminal on a Linux system like Ubuntu. In this piece, we’ll focus specifically on navigating through command-line utilities to monitor disk usage, understand file sizes, and free up space when necessary. As the title suggests, you can expect tips and tricks that will be extremely handy for managing your computer’s hard drive or SSD more efficiently.

Introduction

In the world of Linux, using the terminal is one of the most powerful ways to interact with your system. It offers a wide range of tools for monitoring everything from network connectivity to disk space usage. This article aims to guide you through several methods that can help you keep an eye on available storage space in Ubuntu directly from the command line.

Why Use the Terminal?

The terminal is not just a tool for seasoned Linux users; it’s also incredibly beneficial for beginners looking to understand their system better. Commands like df, du, and others allow you to quickly see how much space is left on your hard drive, identify large files that may be taking up unnecessary room, and take action to clear out space as needed.

Key Tools: df and du

1. The ‘df’ Command

The df (disk free) command provides a quick overview of the amount of disk space available across all mounted file systems on your system. It displays information in terms of total capacity, used space, and available space for each partition or filesystem.

Syntax

df [options] [file...]
  • Options:
    • -h (human-readable): Displays sizes in kilobytes (K), megabytes (M), gigabytes (G) and so on.
    • -a (all files): Shows information about all filesystems, including those mounted without a corresponding mount point.

Example Usage

df -h /home/user

This command will display the disk usage for your home directory in an easily readable format.

2. The ‘du’ Command

The du (disk usage) command helps you find out how much space individual files and directories are using within a given file system. This is particularly useful when trying to identify large files or directories that may be consuming too much disk space.

Syntax

du [options] [file...]
  • Options:
    • -h (human-readable): Similar to df, it provides sizes in kilobytes, megabytes, gigabytes.
    • -s (summary only): Displays the total size for each argument and for each file when listing directories.

Example Usage

du -sh /var/log/*

This command will list the size of all log files under /var/log/.

Detailed Steps to Check Storage Space

Step 1: Opening Terminal in Ubuntu

The first step is simply opening up your terminal. If you’re using a desktop environment like GNOME, you can find the terminal application by searching for it with your system’s search bar or pressing Ctrl + Alt + T on your keyboard.

Step 2: Using ‘df’ Command to Check Overall Disk Usage

To get an overview of all mounted filesystems and their current disk usage status, type the following command into your terminal:

sudo df -hT

The -T option specifies that we want file system types listed along with other details. The sudo part ensures you have root-level permissions for viewing information about all partitions.

Step 3: Identifying Large Files and Directories

Once you know which filesystem or directory is running low on space, use the du command to dig deeper into specific directories to identify large files or folders that may be causing issues.

sudo du -h /path/to/directory/* | sort -n -r | head -10

This command will display the ten largest files in a sorted order based on their sizes under the specified directory. Replace /path/to/directory with your actual path to a specific location you want to investigate.

Step 4: Freeing Up Disk Space

After identifying what’s taking up space, there are various actions you can take:

  • Deleting Unnecessary Files: Use rm for single files and directories.
  • Clear Log Files: Logs often accumulate large amounts of data. You might use commands like journalctl --vacuum-size=10M to clear the logs or manually delete log files if necessary.

Step 5: Verifying Changes

Always verify changes with another run of your previous commands (df, du) to confirm that the space has been freed up as intended.

Conclusion

In summary, managing storage space on Ubuntu through terminal commands offers a flexible and efficient approach. By mastering tools like df and du, you can keep track of disk usage effectively and maintain optimal performance for your system. Whether you’re cleaning up temporary files or monitoring log directories, these techniques are indispensable in any Linux user’s toolkit.

Additional Tips

  • Consider setting up cron jobs to automate regular cleanup tasks.
  • Utilize ncdu (NCurses Disk Usage) as an interactive frontend for du. It provides a more intuitive interface for navigating and analyzing disk usage through the terminal.

With these tips and tools at your disposal, managing storage space in Ubuntu has never been easier or more accessible.

Last Modified: 22/03/2018 - 06:33:48