Categories
Design

How to view free disk space and disk usage from the linux terminal

Use ‘df’ and ‘du’ to check filesystem use at a global or directory level

How to view free disk space and disk usage from the linux terminal

Blend Images / Klaus Tiedge / Brand X Pictures / Getty Images

  • Tweet
  • Share
  • Email

Use the df utility to review a summary of the available and used disk space on your Linux system. With the -h option, it shows the disk space in human-readable form. The du utility, by contrast, lists space utilization on a directory-and-subdirectory basis.

A Linux system consists of one or more filesystems. Unlike Windows computers, a Linux filesystem doesn’t need to be a specific drive partition. Instead, a Linux filesystem includes partitions, clusters of partitions, devices, or sandboxed folders (for example, for Snap packages) that the system treats separately.

Output of the df Command

The output of the df command structures the results into six columns:

  • Filesystem: The name of the filesystem. Filesystems that aren’t temporary (tmpfs) and aren’t physically separate sometimes list as being a loopback device, iterated at /dev/loopnn.
  • 1K-blocks: The number of kilobyte blocks available to the filesystem.
  • Used: The number of blocks used.
  • Available: The number of blocks available. If the filesystem dynamically updates, this value will always be zero. Snap packages, for example, grow and shrink as necessary, so df always lists them as fully used.
  • Use%: The ration of available-to-used blocks.
  • Mounted on: The location where the filesystem is mounted in the system.

How to view free disk space and disk usage from the linux terminal

Output of the du Command

The du command, on the other hand, shows the disk space used by the files and directories in the current directory. The -h option makes the output easier to understand.

How to view free disk space and disk usage from the linux terminal

By default, the du command lists all subdirectories to show how much disk space each has occupied. Consolidate the output with the -s option, which only shows a summary. Unless you run sudo du, however, you’ll see permission-denied errors for any directories to which the logged-in account lacks read access.

To show the disk usage of a directory other than the current directory, insert that directory name as the last argument.

Both du and df admit to several useful but relatively rare command switches. Read the manpages for each command to explore approaches to fine-tune the inputs and the outputs of these commands.

It is not uncommon to have to check the disk or drive on your machine to see if there is enough space left on it. Keeping enough free disk space allows you to save more files and images, install new software and even run the operating system better and faster. The method to check for the current status of the hard disk depends on the operating system itself.

Firstly, list all the hard drives that you have mounted on the system. This will give you the information about the mount point and device names. You can use that to get specific information about each of the disks.

In Linux and Unix operating systems, the command to find the total amount of disk space and the disk space in use is df. df is an abbreviation for Disk Free and this program displays the amount of disk space in Linux that is free for use.

The df command displays the disk space for every mounted file system on your machine, if you do not specify a specific file system or a command line argument in the command line. You can specify the file system name in the command line as an argument if you prefer to see the details of only a particular one.

bash$ df /dev/sda1

The above command example will print out the details for the disk mounted at /dev/sda1.

There are several different options available which allows you to format the output of the command better. Not all of the options are commonly used, hence we will look at just a couple of the more useful options. If you like to see the complete list of options available, refer to the local man page of df or see the online version.

human readable format

-h option prints out the numerical values in kilobytes (KB), megabytes (MB) and gigabytes (GB) which are easier to read.

all file systems

-a option prints out the information for all file systems including the dummy file systems. This is useful if you like to view the file systems like usb and proc.

You can specify the format of the command output by specifying the -P option, which prints out in the standardized POSIX format. This is usually the default in almost all of the latest versions. The output for each of the mounted filesystem is denoted in a single line in the following column order:

All of these fields should be pretty self explanatory. The most important one is obviously the available or free space column which shows you the amount of space left for you to use.

Another command that can be used is fdisk. Though the fdisk command, which stands for Fixed Disk, is not as informative as the previous df command, you can find other details about your mounted disk. It also prints out the total space of the hard disks mounted on your system. Note that you would require super user (or root) role to execute this command.

Use fdisk -l to print out detailed information on your disk partitions

The highlighted region in the screenshot shows where you can find the total disk space of your mounted file system. The rest of the output is useful information which shows you detailed information from your master boot table about your disk partitions.

Keep track of disk utilization with this handy list of commands.

How to view free disk space and disk usage from the linux terminal

Subscribe now

Get the highlights in your inbox every week.

Keeping track of disk utilization information is on system administrators’ (and others’) daily to-do list. Linux has a few built-in utilities that help provide that information.

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

df -h shows disk space in human-readable format

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

df-ha.png

How to view free disk space and disk usage from the linux terminal

df -T shows the disk usage along with each block’s filesystem type (e.g., xfs, ext2, ext3, btrfs, etc.)

df -i shows used and free inodes

df-ti.png

How to view free disk space and disk usage from the linux terminal

You can get this information in a graphical view using the Disks (gnome-disk-utility) in the GNOME desktop. Launch it to see all disks detected by your computer, and click a partition to see details about it, including space used and space remaining.

gnome-disks_space.jpg

How to view free disk space and disk usage from the linux terminal

  • Top 7 terminal emulators for Linux
  • 10 command-line tools for data analysis in Linux
  • Download Now: SSH cheat sheet
  • Advanced Linux commands cheat sheet
  • Linux command line tutorials

du -h shows disk usage in human-readable format for all directories and subdirectories

du -a shows disk usage for all files

du -s provides total disk space used by a particular file or directory

du-has.png

How to view free disk space and disk usage from the linux terminal

The following commands will check your total space and your utilized space.

This information can be represented visually in GNOME with the Disk Usage application, or with Filelight in the KDE Plasma desktop. In both applications, disk usage is mapped to concentric circles, with the middle being the base folder (usually your /home directory, but it’s up to you) with each outer ring representing one directory level deeper. Roll your mouse over any segment for detailed information about what’s taking up space.

Home » SysAdmin » How to Check Disk Space in Linux

How much space do I have free on my Linux drive?

Managing disk space on a Linux server is an important task. For example, package manager applications notify you how much disk space will be required for an installation. For that information to be meaningful, you should know how much space your system has available.

In this tutorial, learn how to use the df command to check disk space in Linux and the du command to display file system disk space usage.

How to view free disk space and disk usage from the linux terminal

  • A Linux-based system
  • A terminal window / command line
  • A user account with sudo or root privileges

Check Linux Disk Space Using df Command

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

How to view free disk space and disk usage from the linux terminal

The df command stands for disk free, and it shows you the amount of space taken up by different drives. By default, df displays values in 1-kilobyte blocks.

Display Usage in Megabytes and Gigabytes

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

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

How to view free disk space and disk usage from the linux terminal

Understanding the Output Format

The df command lists several columns:

Your output may have more entries. The columns should be self-explanatory:

  • Filesystem – This is the name of each particular drive. This includes physical hard drives, logical (partitioned) drives, and virtual or temporary drives.
  • Size The size of the filesystem.
  • Used – Amount of space used on each filesystem.
  • Avail – The amount of unused (free) space on the filesystem.
  • Use% – Shows the percent of the disk used.
  • Mounted on – This is the directory where the file system is located. This is also sometimes called a mount point.

The list of filesystems includes your physical hard drive, as well as virtual hard drives:

  • /dev/sda2 – This is your physical hard drive. It may be listed as /sda1, /sda0, or you may even have more than one. /dev stands for device.
  • udev This is a virtual directory for the /dev directory. This is part of the Linux operating system.
  • tmpfs – You may have several of these. These are used by /run and other Linux processes as temporary filesystems for running the operating system. For example, the tmpfs /run/lock is used to create lockfiles. These are the files that prevent multiple users from changing the same file at the same time.

Display a Specific File System

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

You can also use a backslash:

This displays the usage on your primary hard drive. Use the mount point (in the Mounted on column) to specify the drive you want to check.

Note: The df command only targets a full filesystem. Even if you specify an individual directory, df will read the space of the whole drive.

Display File Systems by Type

To list all file systems by type, use the command:

This lists drives with the ext4 type, in human-readable format.

Display Size in 1000 Instead of 1024

You can display disk usage in units of 1000 instead of 1024:

This can address a point of confusion in storage technology. Hard drive manufacturers sell hard drives in sizes based on 1000 bytes = 1 kilobyte.

However, operating systems divide that space up so that 1024 bytes = 1 kilobyte. Because of this, a 1000-gigabyte hard drive ends up with roughly 930 gigabytes of usable storage.

Check Disk Space in Linux With du Command

The du command displays disk usage. This tool can display disk usage for individual directories in Linux, giving you a finer-grained view of your disk usage. Use it to display the amount of space used by your current directory:

How to view free disk space and disk usage from the linux terminal

Like the df command, you can make du human-readable:

It displays a list of the contents of the current directory, and how much space they’re using. You can simplify the display with the -s option:

This shows how much space the current directory uses.

To specify the directory or file, check use the following options:

With the second command, you may have noticed a permission denied error message. This means the current user doesn’t have the privileges to access certain directories. Use the sudo command to elevate your privileges:

Note: If you’re working on CentOS Linux, you may need to use the su command to switch to the root user to access protected directories.

You should now understand how to use df and du commands to check disk space on your Linux system. Remember, to display a complete list of options, use either df –help or du –help .

Check out our article on how to use fsck command to run a filesystem check as preventive maintenance or when there is an issue with your system.

How to view free disk space and disk usage from the linux terminal

In this tutorial, we are going to show you how to use the df command to check disk space in Linux, and the du command to monitor disk usage. If you’re a Linux user, these two essential tools will help you manage your files more effectively.

Analyzing the Hard Drive

df and du commands have a slightly different purpose when analyzing a hard drive. In order to avoid confusion, we’ll explain them in separate sections. Let’s begin with the df command!

Check Disk Space in Linux Using the df Command

df, which stands for Disk Filesystem, is used to check disk space. It will display available and used storage of file systems on your machine.

When executing this command, you will see the default columns: Filesystem, Size, Used, Available, Use%, and Mounted On. It should look something like this:

How to view free disk space and disk usage from the linux terminal

  • FileSystem — provides the name of the file system.
  • Size — gives us the total size of the specific file system.
  • Used — shows how much disk space is used in the particular file system.
  • Available — shows how much space is left in the file system.
  • Use% — displays the percentage of disk space that is used.
  • Mounted On — tells us the mount point of a particular file system.

By adding a certain option to the df command, you can check the disk space in Linux more precisely. These are the most popular options:

  • df -h — it will display the result in a human-readable format.
  • df -m — this command line is used to display information of file system usage in MB.
  • df -k — to display file system usage in KB.
  • df -T — this option will show the file system type (a new column will appear).
  • df -ht /home — it allows you to view information about a specific file system in a readable format (in this case /home file system).
  • df — help — it lists down other useful options that you can use, complete with their descriptions.

Check Disk Usage in Linux Using the du Command

Another important command is du, short for Disk Usage. It will show you details about the disk usage of files and directories on a Linux computer or server. With the du command, you need to specify which folder or file you want to check. The syntax is as follow:

Let’s take a look at real-world use of the du command with the Desktop directory:

  • du /home/user/Desktop — this command line allows users to see into the disk usage of their Desktop folders and files (subdirectories are included as well).
  • du -h /home/user/Desktop — just like with df, the option -h displays information in a human-readable format.
  • du -sh /home/user/Desktop — the -s option will give us the total size of a specified folder (Desktop in this case).
  • du -m /home/user/Desktop — the -m option provides us with folder and file sizes in Megabytes (we can use -k to see the information in Kilobytes).
  • du -h — time /home/user/Desktop — this informs the last modification date of the displayed folders and files.
  • df –help — it displays a list of available options and what they can be used for.

Step 2 — Combining Commands and Cleaning Disk Space

You can get more information done by combining df and du command with other arguments. By doing this, you will get a better idea of which files you can delete to free up disk space.

Just remember to start with df command to see which file system needs a cleanup the most. After that, you can proceed with these combinations.

Sorting Files By Size

First, we gather files and folders on the Desktop in a readable format using the du command. Then, we pipe the result to the sort command together with the -rn option. The script will sort all the files and folders from largest to smallest to check the disk space use in Linux. The combination should look like this:

Remember that you shouldn’t necessarily delete files just because they are large. If you’re not cautious, you might delete essential files that would break your project.

Excluding by File Size

Let’s say you want to see all files that are above a certain size. The most effective way to do that is by using the command below:

The grep command allows us to search for files based on a specified pattern. In this example, the script will return with any files bigger than 1 GB. If you want to single out 1 MB+ data, you can replace G with M.

Excluding File Types

The last combination is useful when you need to exclude a particular file format from the search results. For instance:

The –exclude=”.txt” argument makes sure the du command will display all file formats except for .txt documents.

Conclusion

df and du commands are file management tools that will check disk space in Linux and display all stored files on your machine. You are allowed to add certain options (like -h, -m, -k, etc.) to refine the output based on your needs.

What’s great, users can get a more specific result by combining du and df with other commands, such as sort, grep, and exclude. Together, they will help you better understand how disk space is used on your server. Be sure to check out our article for more useful Linux commands.

If you have any questions, feel free to comment down below!

Domantas leads the content and SEO teams forward with fresh ideas and out of the box approaches. Armed with extensive SEO and marketing knowledge, he aims to spread the word of Hostinger to every corner of the world. During his free time, Domantas likes to hone his web development skills and travel to exotic places.

Keep track of disk utilization with this handy list of commands.

How to view free disk space and disk usage from the linux terminal

Subscribe now

Get the highlights in your inbox every week.

Keeping track of disk utilization information is on system administrators’ (and others’) daily to-do list. Linux has a few built-in utilities that help provide that information.

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

df -h shows disk space in human-readable format

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

df-ha.png

How to view free disk space and disk usage from the linux terminal

df -T shows the disk usage along with each block’s filesystem type (e.g., xfs, ext2, ext3, btrfs, etc.)

df -i shows used and free inodes

df-ti.png

How to view free disk space and disk usage from the linux terminal

You can get this information in a graphical view using the Disks (gnome-disk-utility) in the GNOME desktop. Launch it to see all disks detected by your computer, and click a partition to see details about it, including space used and space remaining.

gnome-disks_space.jpg

How to view free disk space and disk usage from the linux terminal

  • Top 7 terminal emulators for Linux
  • 10 command-line tools for data analysis in Linux
  • Download Now: SSH cheat sheet
  • Advanced Linux commands cheat sheet
  • Linux command line tutorials

du -h shows disk usage in human-readable format for all directories and subdirectories

du -a shows disk usage for all files

du -s provides total disk space used by a particular file or directory

du-has.png

How to view free disk space and disk usage from the linux terminal

The following commands will check your total space and your utilized space.

This information can be represented visually in GNOME with the Disk Usage application, or with Filelight in the KDE Plasma desktop. In both applications, disk usage is mapped to concentric circles, with the middle being the base folder (usually your /home directory, but it’s up to you) with each outer ring representing one directory level deeper. Roll your mouse over any segment for detailed information about what’s taking up space.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 1m

(a) df command : Report file system disk space usage.

(b) du command : Estimate file space usage.

df command examples to check free disk space

Type df -h or df -k to list free disk space:
$ df -h
OR
$ df -k
Sample outputs that show disk space utilization:

The df utility displays statistics about the amount of free disk space on the specified file system or on the file system of which file is a part. Values are displayed in 512-byte per block counts. The -H option is called as “Human-readable” output. It use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to four or fewer using base 10 for sizes i.e. you see 30G (30 Gigabyte).

How to check free disk space in Linux

To see the file system’s complete disk usage pass the -a option:
df -a
Find out disk usage and filesystem type by passing the -T option:
df -T
Want to get used and free inodes information on Linux? Try:
df -i

du command examples for checking free and used disk space

The du command shows how much space one ore more files or directories is using, enter:
$ du -sh
Sample outputs:

Fig.01: Unix df and du command outputs from my FreeBSD server

Say hello to ncdu command

ncdu (NCurses Disk Usage) is a curses-based version of the well-known ‘du’, and provides a fast way to see what directories are using your disk space. One can install with the following apt command/apt-get command:
sudo apt install ncdu
For RHEL/CentOS, first enable EPEL repo (see CentOS 8 turn on EPEL repo and RHEL 8 enable epel repo) and type the following yum command:
sudo yum install ncdu
Now just type:
ncdu
ncdu [dir] ncdu /etc/

GUI program

Above programs are good if GUI is not installed or you are working with remote system over the ssh based session. Linux and UNIX-like oses comes with KDE and Gnome desktop system. You will find Free Disk Space Applet located under GUI menus. Here is a sample from Fedora Linux version 22 system:

Conclusion

You learned how to keep track of disk utilization, and disk space with various Linux and Unix commands.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 58 comments so far. add one

Last updated March 21, 2021 By Abhishek Prakash 18 Comments

How much disk space I have utilized?

The simplest way to find the free disk space on Linux is to use df command. The df command stands for disk-free and quite obviously, it shows you the free and available disk space on Linux systems.

With -h option, it shows the disk space in human-readable format (MB and GB).

Here’s the output of the df command for my Dell XPS system that has only Linux installed with encrypted disk:

If the above output is confusing for you, don’t worry. I’ll explain a few things around checking available disk space in Linux. I’ll also show the GUI method for desktop Linux users.

With the information you gather, you can go about making some free space on Ubuntu.

Method 1: Checking free disk space in Linux with df command (and understanding its output)

When you use the df command to check disk space, it will show a bunch of ‘file systems’ with their size, used space and free space. Your actual disks should normally be listed as one of the following:

  • /dev/sda
  • /dev/sdb
  • /dev/nvme0n1p

This is not a hard and fast rule but it gives you an indication to easily recognize the actual disk from the crowd.

Your Linux system might have several partitions on your disk for boot, EFI, root, swap, home etc. In such cases, these partitions are reflected with a number at the end of the ‘disk name’, like /dev/sda1, /dev/nvme0n1p2 etc.

You could identify which partition is used for what purpose from its mount point. Root is mounted on /, EFI in /boot/EFI etc.

In my case, I have used 41% of the 232 GB of disk space under root. If you have 2-3 big partitions (like root, home etc), you’ll have to make a calculation here.

How to view free disk space and disk usage from the linux terminalUnderstanding df command output

  • tmpfs: The tmpfs (temporary filesystem) used for keeping files in virtual memory. You can ignore this virtual filesystem comfortably.
  • udev: The udev filesystem is used for storing information related to devices (like USB, network card, CD ROM etc) plugged to your system. You may ignore it as well.
  • /dev/loop: These are loop devices. You’ll see plenty of them while checking disk space in Ubuntu because of snap applications. Loops are virtual devices that allow normal files to be accessed as block devices. With the loop devices, snap applications are sandboxed in their own virtual disk. Since they are under root, you don’t need to count their used disk space separately.

Missing disk space? Check if you have mounted all disks and partitions

Keep in mind that the df command only shows disk space for mounted filesystems. If you are using more than one Linux distribution (or operating systems) on the same disk or you have multiple disks on your system, you need to mount them first in order to see the free space available on those partitions and disks.

For example, my Intel NUC has two SSDs and 4 or 5 Linux distributions installed on them. It shows additional disks only when I mount them explicitly.

How to view free disk space and disk usage from the linux terminalHow to view free disk space and disk usage from the linux terminal

You can use the lsblk command to see all the disks and partitions on your system.

How to view free disk space and disk usage from the linux terminal

Once you have the disk partition name, you can mount it in this fashion:

I hope this gives you a pretty good idea about checking hard drive space on Linux. Let’s see how to do it graphically.

You often hear that disk space is cheap and plentiful. And it’s true that a 4TB mechanical hard disk drive currently retails for less than 100 dollars. But like many users we’ve migrated to running Linux on M.2 Solid State Drives (SSDs). They are NVMe drives reaching read and write speeds of over 5,000MB/s. That’s over 20 times faster than a 7,200 RPM traditional hard drive.

M.2 SSDs do functionally everything a hard drive does, but help to make a computer feel far more responsive. M.2 are NVMe drives which reduce I/O overhead and brings various performance improvements relative to previous logical-device interfaces, including multiple long command queues, and reduced latency. M.2 drives are more expensive than mechanical hard drives in terms of dollar per gigabyte. And M.2 with really large capacities are thin on the ground and expensive, so most users settle for lower capacity drives.

Whatever the size of the hard disk, our disks always fill up over time; it seems data expands to fill any void. This is partly because we run lots of distributions and software. But hard disks always seem to fill up by themselves. Whether you use M.2, other type of SSD, or mechanical hard disk drives, you cannot afford to be rash with storage. When a hard disk is full, it can be very time consuming to sort out and remove offending files and directories.

vizex is a terminal program which helps the user to visualize the disk space usage for each partition and media.

Installation

One way to install vizex is with pip. pip is a general-purpose package installer for both libraries and apps with no environment isolation. We generally prefer pipx though. pipx is made specifically for application installation, as it adds isolation yet still makes the apps available in your shell: pipx creates an isolated environment for each application and its associated packages.

On our Ubuntu systems, pipx is installed with the command:

$ sudo apt install pipx

Then we can use pipx to install vizex with the command:

$ pipx install vizex

You’ll need Python greater than version 3.7. Our modern Ubuntu systems meet this requirement.

How to view free disk space and disk usage from the linux terminal

You’ll notice there are two apps that have been installed: vizex and vizexdf.

There’s other ways to install vizex such as usig a distro-specific package.