Guide
Linux
Intermediate
Disk & Storage Commands
df, du, lsblk, mount, and the commands for inspecting disk usage, partitions, and filesystems on Linux.
Disk & Filesystem Usage
df -h # disk usage per mounted filesystem, human-readable
df -hT # + filesystem type (ext4, xfs, tmpfs...)
df -i # inode usage — a full inode table can block writes even with free space
du -sh /var/log # total size of a directory
du -sh /var/log/* # size of each item inside, one level deep
du -sh * | sort -rh | head -10 # find the biggest space consumers in current directory
df reports what the filesystem thinks is used; du sums actual file sizes. A mismatch (df shows full, du doesn’t add up) usually means a deleted file is still held open by a running process.
Block Devices & Partitions
lsblk # tree view: disks, partitions, and their mount points
lsblk -f # + filesystem type and UUID
sudo fdisk -l # list disks and partition tables (legacy-friendly)
sudo parted /dev/sdb print # partition table for one disk (GPT-friendly)
blkid # UUIDs and filesystem types for all block devices
Mounting
mount # show all currently mounted filesystems
sudo mount /dev/sdb1 /mnt/data # mount manually
sudo umount /mnt/data # unmount
sudo umount -l /mnt/data # lazy unmount (detach now, clean up when no longer busy)
cat /etc/fstab # persistent mount definitions, read at boot
sudo mount -a # mount everything in fstab (also validates it without rebooting)
findmnt /var # show mount details for a specific path
Formatting
sudo mkfs.ext4 /dev/sdb1 # format a partition as ext4
sudo mkfs.xfs /dev/sdb1 # format as xfs
sudo wipefs -a /dev/sdb1 # wipe existing filesystem signatures before reformatting
Finding What’s Eating Disk Space
sudo lsof +L1 # files that are deleted but still held open (space not actually freed)
sudo du -x -d1 / | sort -rh | head -20 # largest top-level directories, staying on one filesystem
ncdu /var # interactive, navigable disk usage explorer (if installed)
Swap
free -h # RAM + swap totals and usage
swapon --show # active swap devices/files
sudo swapoff -a # disable all swap
sudo swapon -a # re-enable swap defined in fstab
LVM Quick Reference
sudo pvs # physical volumes
sudo vgs # volume groups
sudo lvs # logical volumes
sudo lvextend -L +10G /dev/vg_data/lv_app # grow a logical volume
sudo resize2fs /dev/vg_data/lv_app # grow the ext4 filesystem to match
sudo xfs_growfs /app # grow an xfs filesystem (on the MOUNT POINT, not the device)
Production Considerations
- Monitor
df -i(inode usage) alongsidedf -h— a filesystem can report free space but still fail writes with “No space left on device” if inodes are exhausted (common with millions of tiny files, like a poorly-rotated log/cache directory). - A full root filesystem can prevent even SSH login or logging from working — alert well before 90% usage, not at 100%.
xfs_growfstargets the mounted path;resize2fstargets the block device — mixing them up is a common operational mistake.
Quick Interview Answer
“
df -hshows filesystem-level usage,du -shsums actual file sizes in a directory — a gap between them usually means a deleted file is still open (lsof +L1finds it).lsblkandblkidshow the block-device/partition layout,mount/umountmanage active mounts, and/etc/fstabdefines what mounts automatically at boot.”
Common Mistakes
- Ignoring inode exhaustion (
df -i) and only watchingdf -hblock usage. - Deleting a large log file directly instead of truncating it (
> file.log) — the disk space isn’t freed until the writing process closes or restarts. - Running
xfs_growfsagainst a device path instead of the mount point.
Add More Questions to This Guide
Know a question that should be here? Share it and help the community!
Open Google Form