Question: Is it true that Linux defrags the OS automatically? I heard that somewhere but I can’t remember where? I would be grateful for any input. Thank you.
Do you mean defrags the file system?
By design linux file systems try to avoid fragmentation.
It certainly not a routine admin task.
Does any modern OS (Windows, macOS, linux) need defrag these days?
On a 5 year old ext4 I see this analysis:
$ e4defrag -c /shared/Downloads/
e4defrag 1.47.3 (8-Jul-2025)
<Fragmented files> now/best size/ext
1. /shared/Downloads/Python/install-python-windws.cmd.bj~
2/1 6 KB
2. /shared/Downloads/Debian/kinetic/db/release.caches.db
4/1 20 KB
3. /shared/Downloads/Debian/jammy/db/release.caches.db
4/1 20 KB
4. /shared/Downloads/Debian/bookworm/db/release.caches.db
3/1 26 KB
5. /shared/Downloads/MacOSX/Apps/password-store-1.6.3.tar.xz
2/1 26 KB
Total/best extents 85831/43100
Average size per extent 1613 KB
Fragmentation score 1
[0-30 no problem: 31-55 a little bit fragmented: 56- needs defrag]
This directory (/shared/Downloads/) does not need defragmentation.
Done.
And on the server xfs root filesystem that is 10 months old:
$ xfs_db -r -c frag /dev/mapper/luks-...
actual 250428, ideal 249235, fragmentation factor 0.48%
Note, this number is largely meaningless.
Files on this filesystem average 1.00 extents per file
Thanks for your reply Barry. I understand.
Btrfs kinda needs scrubbing to check for data integrity (there’s a package called btrfsmaintenance with a preconfigured systemd service; simply sudo systemctl enable btrfs-scrub.timer), but defrag utilities are largely obsolete.
Defrag is essentially useless for SSD’s.