On Linux and macOS, knowing your linux folder size is a basic part of storage management. The du utility (short for “disk usage”) is the standard tool for this. It calculates how much space a directory occupies and prints the result directly in your terminal.

Checking Linux Folder Size for a Single Directory

To display the linux folder size in a human-readable format, run:

$ du -sh <path>

Here is what each option does:

FlagPurpose
-sRestricts output to the top-level directory only (same as -d 0)
-hConverts raw byte counts into readable units like K (Kilobytes), M (Megabytes), G (Gigabytes)

The <path> argument accepts both relative and absolute directory paths.

For instance, to measure the linux folder size of a directory called server inside your home area:

$ du -sh ~/server
632M   /home/johndoe/server

This tells you the entire server directory takes up 632 Megabytes. If you are new to working with terminal utilities, the beginner’s guide to the Linux command line covers the basics.

Linux Folder Size With Subdirectory Breakdown

Sometimes you need more detail than just the total. You can control how many levels deep the report goes with the -d flag:

$ du -h -d <depth> <path>
ArgumentWhat It Does
<depth>Sets the number of nested levels du will walk through

Setting <depth> to 1 shows every immediate child directory and its individual consumption:

$ du -h -d 1 ~/server
237M   /home/johndoe/server/node_modules
325M   /home/johndoe/server/.next
 32M   /home/johndoe/server/public
 35M   /home/johndoe/server/.git
2.0M   /home/johndoe/server/src
632M   /home/johndoe/server

From this output, you can instantly spot that .next and node_modules are the two heaviest subdirectories. The last line still shows the combined total for the parent directory.

Increasing the depth value to 2 or 3 reveals deeper layers of your directory tree. This is helpful when you are hunting for what exactly is eating up space inside a large project.

Quick Reference for Linux Folder Size Commands

TaskCommand
Total consumption of one directorydu -sh /path/to/folder
Breakdown one level deepdu -h -d 1 /path/to/folder
Breakdown two levels deepdu -h -d 2 /path/to/folder

Practical Tips for Measuring Linux Folder Size

Running du against system directories often throws permission errors. Appending 2>/dev/null to your command silences those warnings so the output stays clean:

$ du -sh /var/log 2>/dev/null

For a broader picture of your partition usage beyond just linux folder size, tools like df can tell you how much free space remains on each mounted filesystem. The disk space guide on commandlinux.com walks through the details.

If you want to verify individual file sizes instead of directories, ls -lh works well. The article on checking file size in Linux explains all the options. You can also look up every available du option on the du man page.

When dealing with scripts that automate disk usage checks, writing a small shell script with du piped to sort -h gives you a ranked list of directories by size. If you are unfamiliar with running shell scripts on Linux, that guide covers permissions and execution methods.

Pairing du with grep lets you filter results for specific directory names. For example, du -h -d 2 /home | grep projects returns only lines containing “projects” from the output.

With just du -sh and du -h -d, you can audit any linux folder size on your system and pinpoint where storage is being used.

FAQs

What does the du command do in Linux?

The du command estimates and displays disk space used by files and directories. It recursively calculates storage consumption and outputs results in bytes or human-readable units.

How do I check linux folder size in one command?

Run du -sh /path/to/folder. The -s flag summarizes the total and -h converts the output into readable units like MB or GB.

What is the difference between du and df commands?

The du command measures space used by specific files and directories. The df command shows total, used, and available space on each mounted filesystem partition.

Why does du show a different size than ls?

The ls -l command shows apparent file size in bytes. The du command reports actual disk space allocated, which is rounded up to the filesystem block size.

How do I fix permission denied errors with du?

Run the command with sudo for full access, or append 2>/dev/null to suppress error messages from directories your user account cannot read.

Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.