Manage storage from the command line — check free space and find what is filling the disk, list the physical disks, mount and unmount a filesystem, and add swap space when memory runs low.
A full disk breaks things in confusing ways, so this is the first check when something misbehaves. df ("disk free") shows how full each mounted filesystem is — -h makes it human-readable (GB/MB). When a disk is full, du ("disk usage") finds the culprit by measuring folder sizes.
How full is each filesystem? (-h = human-readable sizes)
df -hSize of each item in the current folder
du -sh *Find the biggest folders under /var, top 10
sudo du -h /var | sort -rh | headlsblk ("list block devices") draws the storage as a tree: each physical disk (like sda) and the partitions on it (sda1, sda2), with sizes and where each is mounted. It is the clearest picture of what storage the machine actually has — the starting point before adding, mounting, or partitioning anything.
Tree view of disks, partitions, sizes, and mount points
lsblkMore detail including filesystem type and labels
lsblk -fA disk's storage is only usable once it is "mounted" — attached to a folder in the tree. mount device folder attaches it; everything you then write under that folder lands on that disk. umount detaches it safely (do this before unplugging a USB drive). To make a mount survive reboots you would add a line to /etc/fstab, but the live commands are these.
Make a folder to attach the disk to
sudo mkdir -p /mnt/dataAttach partition /dev/sdb1 to that folder
sudo mount /dev/sdb1 /mnt/dataConfirm it's attached (look for /mnt/data)
df -hSafely detach it
sudo umount /mnt/dataSwap is disk space the system uses as overflow when RAM fills up — it keeps a busy machine from crashing under memory pressure (slowly, but alive). free -h shows current memory and swap. You can add a swap file in a few steps: create it, format it as swap, and turn it on.
See current memory and swap usage
free -hCreate a 1G file, mark it as swap, and turn it on
sudo fallocate -l 1G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfileConfirm the new swap is active
free -h