Disk Management Commands

Disk space management sits at the core of routine system administration on Linux and Unix-like operating systems. Whether you are troubleshooting a full filesystem, provisioning a new disk, or planning storage capacity, fluency with disk management commands is an essential skill for any system administrator. This guide covers the most practical and frequently used Linux disk utilities, showing you how to monitor storage, inspect usage, manage partitions, format filesystems, and mount devices reliably.

Monitoring Filesystem Space with df

The df command, short for "disk free," reports the amount of available and used space on mounted filesystems. It is the fastest way to spot partitions that are running out of room.

Common options

  • -h — Print sizes in human-readable units such as KB, MB, or GB. Use this for day-to-day checks.
  • -T — Display the filesystem type, for example ext4, xfs, or tmpfs.
  • -i — Report inode usage instead of block usage. This is useful when a filesystem has plenty of space but has exhausted its inode count.

Practical example

Run the following command to view all mounted filesystems with their types and human-readable sizes:

df -hT

Typical output includes these columns:

  • Filesystem: The device name or remote mount point.
  • Type: The filesystem type in use.
  • Size: Total capacity of the partition.
  • Used: Amount of space already consumed.
  • Avail: Remaining available space.
  • Use%: Percentage of space utilized.
  • Mounted on: The directory where the filesystem is attached in the directory tree.

Watch the Use% column. A partition climbing above 85 or 90 percent is a strong signal that you need to clean up files, expand the disk, or adjust retention policies.

Analyzing Directory and File Sizes with du

While df tells you how much space a whole filesystem has left, du (disk usage) drills down into specific directories and files. It estimates the space consumed by individual items, making it the right tool for finding large folders or runaway log files.

Common options

  • -h — Show sizes in human-readable format.
  • -s — Display only a summary total rather than listing every subdirectory.
  • --max-depth=N — Limit recursion to N directory levels.

Practical example

To see the size of each top-level subdirectory in the current location, sorted from largest to smallest:

du -h --max-depth=1 | sort -hr

This combination is especially effective when you are hunting down which directory is consuming the bulk of your storage.

Managing Disk Partitions with fdisk

fdisk is a classic, MBR-based partitioning utility. It lets you view, create, delete, and modify disk partitions.

Warning: Modifying partition tables is a destructive operation. Back up important data before making changes.

Basic usage

List the partition layout of every disk attached to the system:

sudo fdisk -l

To work on a specific disk, such as /dev/sdb, launch the interactive editor:

sudo fdisk /dev/sdb

Once inside fdisk, these single-letter commands are the most useful:

  • m — Print the help menu.
  • p — Print the current partition table.
  • n — Create a new partition.
  • d — Delete an existing partition.
  • w — Write changes to disk and exit.
  • q — Quit without saving changes.

For modern drives larger than 2 TB, prefer parted or gdisk, which support GPT partition tables.

Formatting Filesystems with mkfs

After creating a partition, you must format it with a filesystem before the operating system can store files on it. mkfs (make filesystem) handles this step.

Common examples

Format a partition as ext4, a general-purpose Linux filesystem:

sudo mkfs.ext4 /dev/sdb1

Format a partition as XFS, a high-performance filesystem often chosen for large enterprise storage:

sudo mkfs.xfs /dev/sdb1

Mounting and Unmounting Filesystems

A formatted partition remains inaccessible until it is mounted to a directory in your filesystem tree.

Mounting a partition

Attach /dev/sdb1 to /mnt/data:

sudo mount /dev/sdb1 /mnt/data

Unmounting a partition

When you no longer need access, detach it with umount:

sudo umount /mnt/data

If the system reports that the target is busy, a process is likely accessing files inside the mount point. Exit the directory or stop the relevant process before retrying.

Configuring Automatic Mounts with /etc/fstab

Mounts created with the mount command disappear after a reboot. To make a partition mount automatically at startup, add an entry to /etc/fstab.

Entry format

Append a line to the file using this layout:

/dev/sdb1    /mnt/data    ext4    defaults    0    2

The fields represent, in order:

  1. Device — The block device path, or preferably a UUID to avoid issues if device names shift between boots.
  2. Mount point — The directory where the filesystem attaches.
  3. Filesystem type — Such as ext4 or xfs.
  4. Mount options — Typically defaults for standard behavior.
  5. Dump — Set to 0 to disable the legacy dump backup utility.
  6. Filesystem check order — 0 skips fsck, 1 is reserved for the root filesystem, and 2 is common for other filesystems.

After editing, run sudo mount -a to validate the configuration. This attempts to mount all filesystems listed in fstab and catches syntax errors before they can prevent the system from booting.

Summary

Proficiency with df, du, fdisk, mkfs, mount, and related utilities gives administrators direct control over storage monitoring and hardware expansion. When executing write operations such as partitioning or formatting, always double-check the target device identifier. A moment of verification prevents accidental data loss and keeps production systems stable.