It's crucial to keep an eye on your Linux system's disk usage and available space to prevent partitions and disks from filling up. Regularly checking the current utilization and remaining free space of your filesystem is a key maintenance task.

Some Linux distributions separate specific directories such as /var and /home into distinct partitions. While this approach has its advantages, it also creates additional failure points and increases the likelihood of individual disks or partitions running out of space independently.

The df command is a widely used Linux tool for monitoring disk utilization. It's a command-line application that checks the filesystem's size, usage, and available space. However, it's not suitable for determining the size of specific files and folders.

Steps to monitor disk space and free space in Linux:

  1. Open the terminal.
  2. Display disk/partition size, usage, and available space using the df command.
    $ df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    tmpfs             399740    1800    397940   1% /run
    /dev/sda3       19991152 7696980  11255632  41% /
    tmpfs            1998688       0   1998688   0% /dev/shm
    tmpfs               5120       0      5120   0% /run/lock
    tmpfs               4096       0      4096   0% /sys/fs/cgroup
    /dev/sda2         524272    7984    516288   2% /boot/efi
    tmpfs             399736     108    399628   1% /run/user/1000
  3. Present usage and available space using df in a human-readable format.
    $ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    tmpfs           391M  1.8M  389M   1% /run
    /dev/sda3        20G  7.4G   11G  41% /
    tmpfs           2.0G     0  2.0G   0% /dev/shm
    tmpfs           5.0M     0  5.0M   0% /run/lock
    tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
    /dev/sda2       512M  7.8M  505M   2% /boot/efi
    tmpfs           391M  100K  391M   1% /run/user/1000

    Unit changed to M(Megabyte), G(Gigabyte), T (Terabyte) etc instead of in blocks.

  4. Display disk usage information for a specific partition.
    $ df -h /dev/sda3
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3        20G  7.4G   11G  41% /
  5. Display disk usage information for a specific mount point.
    $ df -h /boot/efi
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2       512M  7.8M  505M   2% /boot/efi
  6. Show disk usage in a variety of formats and with more details using different df options.
    $ df -hT
    Filesystem     Type   Size  Used Avail Use% Mounted on
    tmpfs          tmpfs  391M  1.8M  389M   1% /run
    /dev/sda3      ext4    20G  7.4G   11G  41% /
    tmpfs          tmpfs  2.0G     0  2.0G   0% /dev/shm
    tmpfs          tmpfs  5.0M     0  5.0M   0% /run/lock
    tmpfs          tmpfs  4.0M     0  4.0M   0% /sys/fs/cgroup
    /dev/sda2      vfat   512M  7.8M  505M   2% /boot/efi
    tmpfs          tmpfs  391M  112K  391M   1% /run/user/1000
  7. Explore additional df command options to better monitor disk size and usage in Linux.
    $ df --help
    Usage: df [OPTION]... [FILE]...
    Show information about the file system on which each FILE resides,
    or all file systems by default.
    
    Mandatory arguments to long options are mandatory for short options too.
      -a, --all             include pseudo, duplicate, inaccessible file systems
      -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                               '-BM' prints sizes in units of 1,048,576 bytes;
                               see SIZE format below
      -h, --human-readable  print sizes in powers of 1024 (e.g., 1023M)
      -H, --si              print sizes in powers of 1000 (e.g., 1.1G)
      -i, --inodes          list inode information instead of block usage
      -k                    like --block-size=1K
      -l, --local           limit listing to local file systems
          --no-sync         do not invoke sync before getting usage info (default)
          --output[=FIELD_LIST]  use the output format defined by FIELD_LIST,
                                   or print all fields if FIELD_LIST is omitted.
      -P, --portability     use the POSIX output format
          --sync            invoke sync before getting usage info
          --total           elide all entries insignificant to available space,
                              and produce a grand total
      -t, --type=TYPE       limit listing to file systems of type TYPE
      -T, --print-type      print file system type
      -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
      -v                    (ignored)
          --help     display this help and exit
          --version  output version information and exit
    
    Display values are in units of the first available SIZE from --block-size,
    and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
    Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).
    
    The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
    Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).
    Binary prefixes can be used, too: KiB=K, MiB=M, and so on.
    
    FIELD_LIST is a comma-separated list of columns to be included.  Valid
    field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
    'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).
    
    GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
    Full documentation <https://www.gnu.org/software/coreutils/df>
    or available locally via: info '(coreutils) df invocation'

    Related: df man page

Discuss the article:

Comment anonymously. Login not required.