If you have ever typed ls -lh into a Linux or macOS terminal looking for whatever is eating up your hard drive, you have probably hit a classic command-line wall: every single directory shows up as 4.0K (or a few hundred bytes on macOS). You know for a fact that your Downloads or node_modules folder contains gigabytes of data, yet ls stubbornly insists it is tiny.
This happens because ls is not lying to you—it is just answering a different question than the one you are asking.
Why ls Shows 4.0K for Massive Folders
In Unix-like operating systems, a directory is essentially a special file that acts like a table of contents. It stores a list of filenames and pointers (called inodes) to where those files actually live on the disk.
When you run ls -lh, the command reads the size of that table of contents, not the combined weight of everything listed inside it. Most Linux filesystems allocate storage in 4-kilobyte blocks, meaning a standard directory index takes up 4.0K of space. Unless a single folder contains tens of thousands of files—forcing the index itself to grow to 8K, 12K, or more—ls will always report 4.0K.
To find out how much space a folder and all its contents actually occupy, you have to switch tools.
The Right Tool: du (Disk Usage)
The standard command for checking folder sizes is du, which stands for disk usage. Unlike ls, du crawls through subdirectories and adds up the actual sizes of the files inside.
To check the size of your current directory without flooding your terminal with thousands of sub-file lines, run:
du -sh
-s(summarize): Gives you only the grand total for the folder rather than listing every subfolder.-h(human-readable): Converts raw byte counts intoK,M, andG.
If you want to see the size of every item sitting inside your current directory—just like ls -lh, but with real folder sizes—use a wildcard:
du -sh *
Tip: The
*wildcard skips hidden files and folders (those starting with a dot, like.gitor.cache). To include hidden items as well, usedu -sh .[^.]* *.
Sorting Folders From Largest to Smallest
Finding out folder sizes is usually step one of freeing up disk space. To immediately spot the biggest storage hogs, pipe the output of du into the sort command:
du -sh * | sort -hr
Here is what makes that combination work:
sort -h: Understands human-readable suffixes so it knows2.1Gis larger than500M(a standard alphabetical sort would put500Mfirst).-r: Reverses the order so the largest directories appear right at the top.
If you are scanning a massive directory with hundreds of folders and only want the top 10 offenders, tack head onto the end:
du -sh * | sort -hr | head -n 10
Modern Alternatives for Visual Disk Exploration
While du is installed on virtually every Unix-based machine on the planet, newer terminal tools make hunting down bloated folders much faster and more visual:
ncdu(NCurses Disk Usage): An interactive terminal interface that scans a directory once and lets you navigate folders with your arrow keys, displaying percentage bars and exact sizes. You can even delete files directly inside the interface.dust: A modern, Rust-based replacement forduthat automatically sorts directories, draws an ASCII tree of your storage usage, and highlights the largest paths in color.gdu: A Go-based disk usage analyzer built specifically for speed on SSDs, offering an interactive layout similar toncdu.
Quick Command Reference
| Goal | Command |
| :— | :— |
| Check total size of the current folder | du -sh |
| Check sizes of all visible folders and files in current location | du -sh * |
| List all items sorted from largest to smallest | du -sh * | sort -hr |
| Show only the 10 largest items in the current folder | du -sh * | sort -hr | head -n 10 |
| Interactively browse folder sizes (if installed) | ncdu |
Making a Shortcut
If you find yourself wishing ls could just do this natively, you can create a custom alias in your shell configuration file (~/.bashrc or ~/.zshrc). Adding the following line lets you type lsize anytime you want a sorted breakdown of folder sizes:
alias lsize='du -sh * | sort -hr'
After saving the file and running source ~/.zshrc (or source ~/.bashrc), you will have a single command that gives you what you originally wanted from ls all along.
Leave a Reply