0
0
Linux CLIscripting~5 mins

Why disk management prevents outages in Linux CLI - Why It Works

Choose your learning style9 modes available
Introduction
Disk management helps keep your computer's storage organized and healthy. It prevents problems like running out of space or corrupted files that can cause your system to stop working.
When your server is running low on disk space and you want to free up space before it causes errors.
When you want to check disk health to avoid unexpected crashes.
When you need to find large files or folders that are taking up too much space.
When you want to clean up temporary files to improve system performance.
When you want to monitor disk usage regularly to prevent outages caused by full disks.
Commands
This command shows how much disk space is used and available on all mounted filesystems in a human-readable format.
Terminal
df -h
Expected OutputExpected
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 30G 18G 63% / tmpfs 1.9G 0 1.9G 0% /dev/shm
-h - Shows sizes in human-readable format like GB or MB
This command shows the total size of the /var/log directory, which often contains large log files that can fill up disk space.
Terminal
du -sh /var/log
Expected OutputExpected
120M /var/log
-s - Summarizes total size instead of listing all files
-h - Shows size in human-readable format
This command deletes old log files to free up disk space and prevent the disk from filling up.
Terminal
sudo rm -rf /var/log/*.old
Expected OutputExpected
No output (command runs silently)
This command lists all block devices like hard drives and partitions to help you understand your disk layout.
Terminal
lsblk
Expected OutputExpected
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk sda1 8:1 0 50G 0 part /
This command checks the filesystem on /dev/sda1 for errors and fixes them to prevent data loss and outages.
Terminal
sudo fsck /dev/sda1
Expected OutputExpected
fsck from util-linux 2.36 /dev/sda1: clean, 12345/327680 files, 67890/1310720 blocks
Key Concept

If you remember nothing else from this pattern, remember: regularly checking and cleaning disk space keeps your system running smoothly and prevents outages.

Common Mistakes
Ignoring disk space warnings until the disk is completely full
A full disk can cause system crashes, failed writes, and data loss.
Regularly monitor disk usage and clean up files before space runs out.
Deleting files without checking what they are
Removing important system files can break your system.
Always verify file purpose before deleting, especially in system directories.
Running fsck on a mounted filesystem
It can cause data corruption if the filesystem is in use.
Run fsck on unmounted filesystems or in recovery mode.
Summary
Use 'df -h' to check disk space usage in a readable way.
Use 'du -sh' to find large directories and clean them if needed.
Use 'fsck' to check and fix filesystem errors to avoid outages.