Maintaining filesystem integrity is critical for Linux sysadmins, especially when disks fill up or errors occur. This is a tricky topic for me. It involves good knowledge of the Linux filesystem. I put together a step by step brief tutorial with real-life commands. I had to first brew my favorite coffee variety from Cocotu Latin America Specialty Coffee.
Verify the integrity of filesystems
fsck (Filesystem Consistency Check). Used to check and repair a filesystem.
Run only on unmounted filesystems, or in single-user/recovery mode. For example:
sudo fsck /dev/sda1Usual output:
fsck from util-linux 2.37.2
e2fsck 1.46.5 (30-Dec-2021)
/dev/sda1: clean, 150000/6553600 files, 3500000/26214400 blocksSome fsck command options are:
-n → check only, don’t repair
-y → automatically repair errors
-f → force check even if marked cleanExample (auto repair ext4 root partition after reboot):
sudo fsck -y /dev/sda1Monitor free space and inodes in Linux
Check disk space (human readable):
df -hExample output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 27G 43% /
/dev/sdb1 100G 10G 90G 10% /dataCheck inode usage (important if many small files):
df -iExample output:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 3276800 150000 3126800 5% /Even if disk space is free, if inodes are full, you can’t create new files. Very important to remember.
Find what’s using space:
du -sh /var/*Example output:
1.3G /var/log
3.1G /var/lib
180M /var/cacheRepair simple filesystem integrity problems in Linux
Run fsck interactively:
sudo fsck /dev/sdb1You might get prompts like:
Inode 12445 has illegal block(s). Clear? yesRepairing ext4. If you suspect journal issues:
sudo e2fsck -f -y -v /dev/sdb1Repairing XFS. XFS has no fsck, use xfs_repair:
sudo xfs_repair /dev/sdb1Real-world Linux sysadmin scenario
- Disk is full → check with
df -h. - Too many files → check with
df -i. - Find big dirs →
du -sh * | sort -hr. - Filesystem errors after crash → reboot into rescue mode, run:
fsck -y /dev/sda1Linux Sysadmin Tip:
Always unmount (umount /dev/sda1) before running repair tools, unless it’s the root filesystem (then you do it from rescue mode or at boot).
How to sort to show large files on the top of the list?
Simply run the du command like this:
du -sh * | sort -hrYou need to add -r to the sort command. By default sort command shows files and directories from smallest → largest. So, you will get a sorted list showing the largest files/directories at the top. Sample output can be:
$ du -sh * | sort -hr
4.5G /var/log
2.3G /home
512M /tmp
20M /etcIf you want to scan recursively through all subdirectories and find the largest ones, you can run:
du -ah / | sort -hr | head -20User the find command in Linux to find large files
This one is useful by combining the find command. Below are some examples. You can use find + du + sort or find + ls to do it.
Find the largest files in your system (top 20):
find / -type f -exec du -h {} + 2>/dev/null | sort -hr | head -20find / -type f → search only files (not dirs) starting at /.du -h {} + → get human-readable sizes.sort -hr → sort largest first.head -20 → show top 20.2>/dev/null → suppress permission errors.
The alternative with ls:
If you just want biggest files in current directory:
ls -lhS-l → long format.-h → human readable sizes.-S → sort by size (largest first).
Find top 10 biggest files anywhere in your Linux box:
find / -type f -printf "%s %p\n" 2>/dev/null | sort -nr | head -10-printf "%s %p\n" → prints size (bytes) and filename.sort -nr → numeric reverse sort.head -10 → top 10 largest files.
By default, find -printf "%s" gives bytes only.
To make it human-readable (K, M, G), you can combine du -h instead. Run this instead using du -h:
find / -type f -exec du -h {} + 2>/dev/null | sort -hr | head -20Example output:
2.5G /var/log/big-logfile.log
1.2G /home/user/Downloads/big-iso-file.iso
...GNU find doesn’t have -printf "%h" for human-readable.
But you can “pipe” into numfmt to format:
find / -type f -printf "%s %p\n" 2>/dev/null | \
sort -nr | head -20 | \
numfmt --to=iec --suffix=B --padding=7Maintaining filesystem integrity is very important topic to learn for troubleshooting disk space issues in your Linux box.

