Linux Disk and Storage
Learn how to inspect disk space, mount filesystems, archive data, compress files, and find large files in Linux.
Why Storage Skills Matter
Disk issues are some of the most common Linux problems. Applications fail when logs fill a partition, backups consume unexpected space, or a new disk is not mounted correctly.
DevOps engineers need to answer questions like:
- how much free space is left?
- which directory is using it?
- what disks are attached?
- is the filesystem mounted where I expect?
Checking Space with df
df reports filesystem-level disk usage.
df
df -h
-h shows human-readable sizes such as G and M.
Example:
df -h /var
This is useful when a specific path is having storage issues.
Measuring Directory Usage with du
du shows how much space directories and files consume.
du -sh /var/log
du -sh *
du -ah /var/log | sort -h
Common flags:
-ssummary only-hhuman-readable-ainclude files
df tells you how full the filesystem is. du helps you find what is taking the space.
Viewing Block Devices with lsblk
lsblk lists block devices such as disks and partitions.
lsblk
lsblk -f
This shows device names, sizes, mount points, and sometimes filesystem types.
It is especially useful after attaching a new cloud volume.
Mounting and Unmounting
Linux makes filesystems available by mounting them into the directory tree.
Mount a device:
sudo mount /dev/xvdf1 /mnt/data
Unmount it:
sudo umount /mnt/data
The command is umount, not unmount.
Note: A filesystem usually cannot be unmounted if processes are actively using it.
Persistent Mounts with /etc/fstab
To mount a filesystem automatically at boot, add it to /etc/fstab.
Example entry:
UUID=1234-ABCD /data ext4 defaults,nofail 0 2
Fields define the device, mount point, filesystem type, options, and fsck order.
A broken /etc/fstab entry can cause boot problems, so edit carefully and test before rebooting.
Creating Archives with tar
tar is the standard archiving tool on Linux.
Create an archive:
tar -cvf backup.tar project/
Extract an archive:
tar -xvf backup.tar
Common flags:
-ccreate-xextract-vverbose-ffile name
Compressing with gzip and gunzip
gzip compresses files.
gzip app.log
gunzip app.log.gz
It is often combined with tar:
tar -czvf backup.tar.gz project/
tar -xzvf backup.tar.gz
Here -z tells tar to use gzip compression.
Working with zip and unzip
Some teams or tools prefer the ZIP format.
zip -r site.zip site/
unzip site.zip
ZIP is especially common when exchanging files across platforms.
Finding Large Files
When a disk fills up, you often need to find the biggest offenders.
A practical approach:
du -ah /var | sort -h | tail -n 20
Another useful pattern:
find /var -type f -size +100M
This finds files larger than 100 MB.
Real-World Scenario
Suppose alerts say /var is 95% full. You might investigate with:
df -h /var
du -sh /var/log/*
find /var/log -type f -size +100M
If one log file grew unexpectedly, you now know where to focus.
Or imagine attaching a new volume to a cloud VM. You could verify it with:
lsblk
sudo mount /dev/xvdf1 /mnt/data
df -h /mnt/data
That confirms the device exists, is mounted, and has usable space.
Test Your Understanding
Let's see how well you understood the concepts! These exercises will help reinforce what you just learned.
Exercise 1: Checking filesystem capacity
Question: Which command from the lesson tells you the free space available on mounted filesystems such as /var?
Exercise 1: Checking filesystem capacity
Choose the command that reports mounted filesystem usage and free space.
Exercise 2: Configuring persistent mounts
Question: Which file should you edit to make a filesystem mount persist automatically at boot?
Exercise 2: Configuring persistent mounts
Identify the configuration file used for boot-time filesystem mounts.
Exercise 3: Building a compressed backup
Question: Which tar command from the lesson creates a gzip-compressed archive of the project directory?
Exercise 3: Building a compressed backup
Choose the tar invocation that both archives and gzip-compresses a directory.