Linux Disk and Storage Management Commands
Linux provides powerful command-line tools for checking disk usage, inspecting storage devices, managing filesystems, and troubleshooting storage problems. These commands are useful for both desktop users and system administrators.
Why Learn Linux Storage Commands?
Disk space and storage problems can cause applications to fail, logs to stop writing, and systems to become unstable. Linux storage commands help identify available space, locate large files, and understand how disks and filesystems are being used.
Inspect Disk → Check Space → Find Large Files → Check Filesystem → Mount Storage → Monitor Usage
Checking Disk Space with df
The df command displays available and used disk space for mounted filesystems.
df -h
df -Th
Checking Directory Usage with du
The du command shows how much disk space files and directories are using. It is useful for finding directories that consume large amounts of storage.
du -sh /var/log
du -sh *
du -h --max-depth=1
Listing Storage Devices with lsblk
The lsblk command displays information about block devices such as disks, partitions, and logical volumes.
lsblk
lsblk -f
Checking Disk Information with fdisk
The fdisk command can display and manage disk partition tables. Use partitioning commands carefully because incorrect changes can result in data loss.
sudo fdisk -l
Understanding Filesystems
A filesystem defines how data is organized and stored on a storage device. Linux supports filesystems such as ext4, XFS, Btrfs, and others.
| Filesystem | Common Use | General Characteristic |
|---|---|---|
| ext4 | General Linux systems | Mature and widely supported |
| XFS | Servers and large filesystems | Designed for scalability |
| Btrfs | Advanced storage management | Supports snapshots and other features |
Mounting a Filesystem
The mount command attaches a filesystem to a directory in the Linux filesystem hierarchy.
sudo mount /dev/sdb1 /mnt/data
mount | grep /mnt/data
Unmounting Storage
The umount command safely detaches a mounted filesystem. The filesystem should not be actively used when unmounting it.
sudo umount /mnt/data
Checking Inodes
A filesystem can run out of inodes even when free disk space remains. The df -i command displays inode usage.
df -i
Linux Storage Command Table
| Command | Purpose | Example |
|---|---|---|
| df | Check filesystem space | df -h |
| du | Check directory usage | du -sh /var/log |
| lsblk | List block devices | lsblk -f |
| fdisk | Inspect partitions | sudo fdisk -l |
| mount | Mount a filesystem | sudo mount /dev/sdb1 /mnt/data |
| umount | Unmount a filesystem | sudo umount /mnt/data |
Example Storage Troubleshooting Scenario
Application Fails → Check df -h → Find Full Filesystem → Use du → Locate Large Data → Clean or Expand Storage
Common Linux Storage Problems
- Filesystem running out of space
- Too many files consuming inodes
- Large log files
- Incorrect mount configuration
- Unmounted storage devices
- Filesystem errors
Common Mistakes to Avoid
- Deleting files without checking their purpose
- Running partitioning commands without backups
- Unmounting an active filesystem
- Ignoring inode usage
- Editing filesystem configuration incorrectly
Advanced Linux Storage Concepts
- Logical Volume Management
- RAID
- Filesystem snapshots
- Disk quotas
- Storage encryption
- Network-attached storage
- Persistent storage for containers
Practice Exercises
- Check available disk space
- Find the largest directories
- List all block devices
- Identify mounted filesystems
- Check inode usage
- Mount a test filesystem
- Safely unmount the filesystem
Conclusion
Linux disk and storage commands make it easier to understand how storage is being used and to troubleshoot common filesystem problems. Commands such as df, du, lsblk, mount, and umount are essential tools for Linux administration.