Linux logo

How to Check Disk Space in Linux OS

You can monitor the disk space of your Linux system through various methods, whether it’s using a third-party program that provides an overview of available disk space or employing command-line tools in the Linux Terminal.

Effectively managing disk space on a Linux server is an essential and continuous task.

For instance, package manager software informs you about the disk space required for installations. To interpret this information accurately, it’s crucial to have a clear understanding of the available space on your system.

In Linux, two key commands for checking disk space are df, indicating disk space free, and du, indicating disk space used.

Now let’s take a look at both commands.

The du command

Let us first look at the du command which stands for Disk Used.

With this utility, we can assess directory disk utilization.

$ du [option]… [file]

An example command using du

The simplest command for disk used can be:

$ du

This displays the used space of the current directory.

You can make du human-readable:

$ du -h

It displays a listing of the contents of the current directory, and how much space they are using.

Using -hs

du --hs

You can simplify the screen with the –s option. This shows how much space the current directory uses.

Getting help – list all available options

The –help will display available options of du command. Run this command:

$ du --help

linux space du

The -s, –summarize option

The -s flag is added to the -h flag on occasion. With their powers combined, they enable us to receive an overview of the directory’s use in a human-readable format.

For example:

$ du -sh
The –time option in du command

It shows the time of the last modification to any file in the directory or subdirectory which you run it against.

$ du -ah --time
The -c, –complete

This choice is much more of a dummy test than it’s useful, but some people really like using a entire measurement output. The -c flag adds a line to the bottom of the output that provides you a grand total of each the disk usage for the file path given.

$ du -ch
The df command

The df command stands for “disk-free” and shows available and used disk space on the Linux system.

You can check your disk space simply by opening a terminal window and entering the following:

$ df

The -a shows the file system’s complete disk utilization even if the Available field is 0

$ df -a

Note: By default, the df displays values in 1-kilobyte blocks.

Further Reading:  What is Linux tail command?
Display Utilization in Megabytes and Gigabytes

You can display disk usage in a more human-readable format by adding the –h option:

$ df -h

This shows the size in kilobytes (K), megabytes (M), and gigabytes (G).

Display information in megabytes

Use the –m option to get information in megabytes. Example command:

$ df –m
The –T option

The -T option shows the disk usage along with every block’s file system type (e.g., xfs, ext2, ext3, btrfs, etc.. )

$ df -T
Display file system inodes

The -i shows used and free inodes. i.e.

$ df -i

Display a Particular File System

The df command may be used to display a specific file system:

$ df –h /dev/tst
Graphical view to check Disk

You can receive this data in a graphical view with the Disks (gnome-disk-utility) from the GNOME desktop. Launch it to find all discs detected by your computer, and click on a partition to find details about it, such as space used and space remaining.

Check these GUI tools:

Disks

Ncdu

Best Practices for Checking Disk Space in Linux

Checking disk space on a Linux system is crucial for efficient system management and maintenance. Two primary commands, df and du, offer insights into disk usage and availability. Here are best practices to effectively check disk space on a Linux OS:

  1. Regular Disk Space Checks:
    • Schedule regular disk space checks to stay informed about system storage status.
    • Automate disk space monitoring using tools like cron jobs to receive periodic reports.
  2. Understanding File System Usage:
    • Utilize the df command to understand overall file system usage.
    • Use df -h for a human-readable format, providing size information in kilobytes, megabytes, and gigabytes.
  3. File System Type Identification:
    • Employ the df -T option to identify the file system type associated with each block.
    • This information is valuable for compatibility and system-specific considerations.
  4. Inodes Analysis with df:
    • Use df -i to check the usage and availability of inodes on the file system.
    • Understanding inode utilization is crucial for managing file and directory structures.
  5. Disk Utilization Details with du:
    • Leverage the du command to analyze disk utilization at the directory level.
    • Use du -h for human-readable output, providing details on space usage by directories.
  6. Simplified Disk Utilization Summary:
    • Combine the -s option with du -h (du -sh) to obtain a simplified summary of directory disk utilization.
    • This provides an overview without listing every subdirectory.
  7. Time of Last Modification:
    • Explore the --time option with du to include the time of the last modification for files in the directory.
    • Useful for tracking changes and understanding recent updates.
  8. Complete Disk Utilization Overview:
    • For a comprehensive overview, use the -c option with du to obtain a grand total of disk usage.
    • While not always practical, it can be helpful for specific scenarios.
  9. Graphical Disk Information:
    • Consider using graphical tools like Disks (gnome-disk-utility) for a visual representation of disk information.
    • Graphical tools provide an intuitive interface to inspect disk partitions and their details.
  10. File System-specific Checks:
    • Conduct file system-specific checks using df for a particular file system (df -h /dev/[filesystem]).
    • This allows targeted analysis of individual partitions.
  11. Human-readable Disk Size Units:
    • Always use human-readable size units (-h, -m, -g) with commands like df and du for better readability.
    • This simplifies the interpretation of disk space information.
Further Reading:  Create New Directory in Linux/Unix by mkdir

By incorporating these best practices, system administrators and users can effectively monitor and manage disk space on a Linux system, ensuring optimal performance and storage utilization. Regular checks and understanding the available tools contribute to a proactive approach to disk space management.

Summarizing Checking Disk Space

Managing disk space on a Linux server is a critical aspect of system maintenance, and Linux provides two powerful commands, df and du, to check disk space effectively. Here’s a summary of the key points covered in this tutorial:1. Disk Usage with du Command:

  • The du command, short for Disk Used, assesses disk utilization for directories.
  • Basic usage: $ du [option]… [file] where an example command is $ du to display the used space in the current directory.

2. Human-Readable Output:

  • Make du output human-readable with -h option: $ du -h.
  • -hs simplifies the screen, providing a summary of the current directory’s usage.

3. Help and Available Options:

  • Access help and list available options with --help: $ du --help.
  • Explore additional options like -s for summarizing disk usage and --time to show the last modification time.

4. Overview with du -sh:

  • Combine options for an overview of the directory’s disk usage in a human-readable format: $ du -sh.

5. Disk Free with df Command:

  • The df command (disk-free) displays available and used disk space on the Linux system.
  • Basic usage: $ df.

6. Complete Disk Utilization Overview:

  • Add the -a option to display complete disk utilization, even if the available field is 0: $ df -a.
  • Display information in kilobytes, megabytes, and gigabytes using -h option: $ df -h.

7. Display Information in Megabytes:

  • Utilize the -m option to display disk usage in megabytes: $ df -m.

8. File System Type with -T Option:

  • Use the -T option with df to show disk usage along with the file system type: $ df -T.

9. Display File System Inodes:

  • Check used and free inodes with the -i option: $ df -i.

10. Display Specific File System: – Display information for a specific file system, e.g., /dev/tst: $ df -h /dev/tst.

11. Graphical Tools for Disk Inspection: – Explore graphical tools like Disks (gnome-disk-utility) for a visual representation of disk information. – Graphical tools provide an intuitive interface to inspect disk partitions, including space used and remaining.

Further Reading:  How to Copy Directory in Linux

Conclusion: Effectively managing disk space involves understanding the usage patterns, utilizing command-line tools like du and df, and, if preferred, exploring graphical tools for a user-friendly experience. Regular monitoring and awareness of disk space contribute to the overall health and performance of a Linux system.