Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

df

Show how much space is used and free on each mounted file system.

Level
RHCSA exam
Group
Disks and file systems
Needs root
No
Package
coreutils

What it does

df (disk free) lists the mounted file systems with their size, used space, free space, use percentage and mount point. It is the first command when somebody says "the disk is full".

With -h sizes are easy to read; with -T you also see the type (xfs, ext4, tmpfs, nfs). With -i it shows inodes: a disk can also be "full" when all inodes are used (millions of tiny files), even if there is free space.

How to write it

df [OPTION]... [FILE]...

Options 18

Most used

-h, --human-readable
Sizes in powers of 1024, like 950M or 17G.
-T, --print-type
Show the file system type.
-i, --inodes
Show inode use instead of block use.
-H, --si
Sizes in powers of 1000 (like disk makers use).
-a, --all
Also show pseudo, duplicate and inaccessible file systems.
-l, --local
Only local file systems (no NFS or CIFS).
-t, --type=type
Only file systems of this type, like xfs.
-x, --exclude-type=type
Leave out this type, like tmpfs.
-k
Sizes in 1 KiB blocks.
-B, --block-size=size
Sizes in this unit, like M or G.
--output[=<fields>]
Choose the columns: source, fstype, itotal, iused, iavail, ipcent, size, used, avail, pcent, file, target.
--total
Add a line with the total.
-P, --portability
Use the POSIX output format (one line per file system, good for scripts).
--sync
Run sync before reading the numbers.
--no-sync
Do not run sync first (the default).
-v
Ignored.
--help
Show help.
--version
Show the version.

Examples 11

$ run as a normal user# run as root (or with sudo)

  1. 1Show all file systems with readable sizes

    df -h

    Look at the Use% column. Above 90% needs action.

  2. 2Show the types too

    df -hT

    You see which ones are xfs, ext4, tmpfs or NFS.

  3. 3Which file system holds this folder?

    df -h /var/log

    Shows the file system that the folder is on.

  4. 4Check inodes when the disk is "full" but has space

    df -i /var

    100% IUse% means no new files can be made. Look for folders with millions of small files.

  5. 5Only real disks, no tmpfs

    df -h -x tmpfs -x devtmpfs

    A cleaner list for reports.

  6. 6Only XFS file systems

    df -hT -t xfs

    Useful when you check the volumes you created in the LVM chapter.

  7. 7Choose the columns for a report

    df -h --output=target,size,used,avail,pcent

    Easy to read and to paste in a ticket.

  8. 8Alert when a file system is above 85% (monitoring script)

    df -P | awk 'NR>1 && $5+0 > 85 {print "WARN", $6, $5}'

    -P keeps each file system on one line, so awk reads it safely.

  9. 9Check a new mount

    mount /dev/vdb1 /mnt/data && df -h /mnt/data

    Confirms the size and that the mount worked.

  10. 10Only local file systems

    df -hl

    Skips NFS shares that may hang when the server is down.

  11. 11Show the total of all file systems

    df -h --total | tail -1

    One number for the whole server.

Watch out

  • df and du can disagree: a deleted file that a program still has open still uses space. Find it with lsof +L1.
  • XFS and ext4 keep some space reserved; "Avail" can be smaller than Size minus Used.
  • A hanging NFS server can make df hang. Use df -l or df -x nfs4.

Files

/proc/self/mountinfo
The list of mounts that df reads.

Tips to remember

  • df -hT = which disk, how full, what type. df -i = inodes.
  • df = per file system, du = per folder.