How to use the df command in Linux

29 ago 2024 2 min di lettura
How to use the df command in Linux
Indice dei contenuti

Introduction

The df (disk free) command is an essential tool in Linux for displaying detailed information about disk space usage. This command is especially useful for monitoring and managing your system's storage resources. This tutorial will walk you through the basics of df, showing you how to use it in various scenarios to improve your efficiency in managing Linux systems.

Prerequisites

Before you begin, make sure you have:

  • An installed and working Linux system.
  • Command line (terminal) access.

Installation

The df command is usually preinstalled on all Linux distributions. However, if for some reason it is not available, you can install it using your distribution's package manager. For example, on Debian/Ubuntu:

sudo apt-get install coreutils

On Red Hat/CentOS:

sudo yum install coreutils

Basic usage

The simplest way to use df is to get an overview of disk space usage on all mounted partitions:

df

This command will print a table with information about each partition, including file system, total size, used space, available space, and mount point.

Advanced usage

View in megabytes or gigabytes

To display the size in megabytes or gigabytes, use the -m or -h options respectively:

df -m
df -h

The -h (human-readable) option is particularly useful because it formats the size into a more human-readable format, such as MB or GB.

View Information about a specific file system

You can get information about a specific file system by specifying the mount point:

df /dev/sda1

View information about all file systems including unmounted ones

To display information about all filesystems, including unmounted ones, use the -a option:

df -a

View information about specific file systems types

You can filter filesystems by type using the -t option followed by the filesystem type:

df -t ext4

This command will only show ext4 file systems.

Practical examples

Example 1: disk space monitoring

Suppose we want to regularly monitor the disk space of our main partition:

df -h /

Example 2: check disk space on all partitions

To get a complete overview of disk space on all partitions:

df -hT

The -T option also shows the file system type.

Example 3: checking disk space on unmounted file systems

To check disk space on all file systems, including unmounted ones:

df -ah

Conclusion

The df command is an essential tool for anyone working with Linux systems. With its many options, df allows you to monitor and manage your system's storage resources efficiently and accurately. Experiment with the various flags and combinations to take full advantage of this command's potential.

Support us with a

Successivamente, completa il checkout per l'accesso completo a Noviello.it.
Bentornato! Accesso eseguito correttamente.
Ti sei abbonato con successo a Noviello.it.
Successo! Il tuo account è completamente attivato, ora hai accesso a tutti i contenuti.
Operazione riuscita. Le tue informazioni di fatturazione sono state aggiornate.
La tua fatturazione non è stata aggiornata.