brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ls -lhS puts the biggest files in a folder at the top

Files
~/tips/tip-files-ls-sort-by-size

ls -lhS /var/log

Sort a directory listing by size, with readable units.

When a folder is larger than it should be, I start with the plain listing, sorted by size. No extra tool needed.

Add -S to the usual long listing:

ls -lhS /var/log

-l shows the details, -h prints sizes like 3.7M or 29M, and -S sorts largest first. To see only the top entries:

ls -lhS /var/log | head

The first line of the output is the total, so head gives you that plus nine files. Flip the order with -r when you want the biggest ones at the bottom, right above your prompt:

ls -lhSr /var/log

Hidden files stay hidden unless you add -A, and a large dotfile is easy to miss that way.

The limit is folders. ls shows the size of the directory entry itself, often 4.0K, and says nothing about what is inside. A subfolder with gigabytes in it looks tiny in this list. For that question use du. Also, it only sorts the folder you point at, and sparse files such as some disk images can claim more size than they use on disk.

Further reading: What information is listed (ls), Sorting the output (ls)

More Files tips sha256sum -c --ignore-missing SHA256SUMS xxhsum -H64 backup.tar > backup.xxh unzip -j archive.zip -d out/ Files > More > Select > pick files > More > Compress file photo.jpg data.bin All Files tips (15) All topics

Link