Tools › Cheat sheets › System Administration › Disks & storage
💽

Disks & storage cheat sheet

Commands for finding what is using disk space and for working with block devices. Commands that write to devices are marked as destructive; always double-check the device name.

Click any command to copy it.

Disk space

CommandWhat it does
df -hFree and used space per filesystem.
df -iInode usage (a full inode table looks like a full disk).
du -sh dirTotal size of a directory.
du -h --max-depth=1 . | sort -hSize of each subdirectory, smallest to largest.
du -ah . | sort -rh | head -20The 20 biggest files and folders below here.
ncdu /Interactive disk usage browser (install ncdu first).
sudo lsof +L1Deleted files still held open, a common cause of 'missing' space.

Devices and filesystems

CommandWhat it does
lsblkList block devices as a tree.
lsblk -fInclude filesystem type, label and UUID.
sudo blkidShow UUIDs and types of devices.
sudo fdisk -lList disks and partitions.
findmntShow mounted filesystems as a tree.
sudo smartctl -a /dev/sdaShow SMART health data (install smartmontools).

Mount

CommandWhat it does
sudo mount /dev/sdb1 /mntMount a partition.
sudo umount /mntUnmount it.
sudo mount -o ro /dev/sdb1 /mntMount read-only.
UUID=xxxx /data ext4 defaults,nofail 0 2Example /etc/fstab line for mounting at boot.
sudo mount -aMount everything in fstab (a good test for typos).
sudo umount -l /mntLazy unmount of a busy filesystem.

Format and repair

CommandWhat it does
sudo mkfs.ext4 /dev/sdb1Destructive: Create a new ext4 filesystem, destroying all data on the partition.
sudo fsck /dev/sdb1Check and repair a filesystem (unmount it first).
sudo wipefs -a /dev/sdbDestructive: Erase filesystem signatures from a device.
sudo dd if=image.iso of=/dev/sdX bs=4M status=progressDestructive: Write an image directly to a device. A wrong device name destroys data.
sudo resize2fs /dev/sdb1Grow an ext4 filesystem to fill its partition.

LVM

CommandWhat it does
sudo pvs; sudo vgs; sudo lvsSummarise physical volumes, volume groups and logical volumes.
sudo lvextend -r -L +10G /dev/vg/lvGrow a logical volume by 10 GB and resize its filesystem.
sudo lvcreate -L 20G -n data vgCreate a 20 GB logical volume.
iostat -x 1Per-device I/O statistics every second (install sysstat).

Frequently asked questions

My disk is full but du shows little. Why?

Deleted files held open by a running process still use space (check lsof +L1), or you may have run out of inodes (check df -i).

How do I find the biggest directories?

Run du -h --max-depth=1 . | sort -h from the top and keep drilling into the largest entry, or use ncdu.

More System Administration cheat sheets

⚙️ systemctl📜 journalctl📦 apt🎩 dnf / yum👥 Users & groups📊 Processes & performance🔄 rsync⏱️ Cron expressionsAll System Administration cheat sheets →
Copied to clipboard