• September 26, 2025

Master Linux Directory Size Checks: du, ncdu & Troubleshooting Guide

You're staring at a No space left on device error. Again. That sinking feeling hits – where did all your disk space go? I've been there too. Last year, my server crashed during peak traffic because the log directory ballooned to 40GB overnight. That's when I realized mastering Linux directory size checks isn't optional – it's survival.

Why You Can't Ignore Directory Sizing

Disk space issues creep up like uninvited guests. One minute everything's fine, next minute your database crashes or system updates fail. I once spent three hours troubleshooting a failed upgrade only to discover /var was 99% full. Knowing how to linux check directory size saves headaches and downtime. We'll cover:

• Immediate commands for quick checks
• Deep analysis tools for storage audits
• Sorting and filtering tricks
• Permission workarounds
• Hidden gotchas that waste hours

The du Command: Your Swiss Army Knife

Let's start with du (disk usage). Basic but essential. I use this daily on my Ubuntu servers. The bread-and-butter syntax:

du -sh /path/to/directory

That -s gives the summary total, -h makes it human-readable (MB/GB). Want specifics? Check these variations:

Essential du Variations

CommandUse CasePersonal Preference
du -sh *Show all items in current dirMy morning "coffee check"
du -h --max-depth=1Depth-limited scanningSaves hours on large trees
du -ch /var/log/* | grep totalGet cumulative total onlyFor reports
sudo du -sh /rootSize with root access(Annoying but necessary)

Sorting is where du shines. Found a space hog? Try:

du -h --max-depth=1 / | sort -h

That sort -h handles human-readable sizes. Crucial. I learned this after manually converting KB/MB for 20 minutes once. Never again.

Watch out: Scanning entire filesystems (du /) can take hours. Use --max-depth or target specific directories.

When du Isn't Enough: Advanced Tools

Sometimes du feels like using a hammer for surgery. Enter these lifesavers:

ncdu: The Visual Explorer

Install with sudo apt install ncdu (Debian/Ubuntu) or sudo yum install ncdu (RHEL/CentOS). Why I love it:

ncdu /home

You get an interactive interface showing directory percentages. Hit d to delete right there. Found 8GB of obsolete Docker images this way last week.

KeybindAction
↑↓Navigate directories
EnterDrill down
dDelete selected
gToggle percentages

Baobab: For GUI Lovers

Installed by default on GNOME systems. Launch with baobab. Shows sunburst charts – perfect for visual learners. My junior devs prefer this for quick linux check directory size tasks.

Special Case Survival Guide

Real-world sizing isn't textbook-perfect. Here's how I handle messy situations:

Cross-Filesystem Headaches

du loves traversing mounted drives. To stop it:

du -h --exclude="/mnt/*" --max-depth=1 /

Or use the -x flag:

sudo du -xh /

That -x saved me from scanning a 10TB network share last month. Lifesaver.

Permission Denied Errors

You'll see this scanning system directories. Solutions:

  • Elevate carefully: sudo du -sh /var/log
  • Redirect stderr: du -sh /* 2>/dev/null
  • Find workarounds: Use df -h for partition-level checks

Symbolic Link Traps

By default, du ignores symlinks. To follow them:

du -Lh /path

Warning: This can cause double-counting! I learned this the hard way when my backup script reported 200% disk usage.

Pro Filtering Techniques

Finding needles in haystacks requires sharp filters. My go-to combos:

Exclude Specific Patterns

du -h --exclude='*.log' --exclude='cache' /var

Find + du Power Combo

find /home -type d -exec du -sh {} + | sort -h

This locates directories over 1GB:

find / -type d -size +1G -exec du -sh {} + 2>/dev/null

Disk Usage vs Actual Size: The Hidden Gap

Why does du report 12GB when ls -l shows 9GB? Two culprits:

  1. Block size overhead: Files consume 4K blocks minimum (even 1-byte files)
  2. Sparse files: Virtual machines love these

Check real vs allocated space:

du -h --apparent-size /path  # Actual file sizes
du -h /path                  # Disk blocks used

FAQs: Your Burning Questions Answered

Why does checking directory size hang on large directories?

Likely traversing network mounts or millions of files. Use --max-depth=1 first. On my NAS, scanning the root directory takes 2 hours – depth limiting cuts it to 3 minutes.

How to exclude hidden directories when checking size?

Use pattern exclusion: du -h --exclude=".*" /home. Though honestly, dotfiles rarely eat significant space.

What's faster between du and ls for size checks?

ls -l only shows file metadata. du scans disk blocks. For directory totals, du is irreplaceable.

How to track directory size changes over time?

Log outputs: date >> size_log.txt; du -sh /target >> size_log.txt. I have cron jobs doing this for critical directories.

Tool Comparison: When to Use What

ToolBest ForSpeedDepthMy Verdict
du -shQuick single-dir checks★★★★★ShallowDaily driver
du --max-depthMulti-level analysis★★★☆☆CustomWeekly audits
ncduInteractive exploration★★★★☆DeepCrisis mode
find + duTargeted hunting★★☆☆☆PreciseForensics

Personal Pitfalls to Avoid

After 10 years managing Linux systems, here's what I wish I knew:

1. Never run recursive du as root on /
Fills logs with permission errors. Use sudo du -x --max-depth=3 / | sort -h instead.

2. Remember sort -h exists
I manually converted sizes for years before discovering it. Don't be like me.

3. Check mount points first
90% of "disappeared" space is separate partitions. df -h before diving into linux directory size checking.

Putting It All Together: My Workflow

When alerts scream "DISK SPACE CRITICAL":

  1. Run df -h to locate full partitions
  2. Quick scan: sudo du -h --max-depth=1 /problem | sort -h
  3. For deep dives: ncdu /problem
  4. Clean with interactive deletion

Monthly maintenance? Automated scripts logging directory sizes. Catching growth trends early prevents 3AM emergencies.

Mastering linux check directory size commands transforms storage management from panic-driven to proactive. Start with du -sh, graduate to ncdu, and always – always – remember sort -h.

Leave a Message

Recommended articles

How to Perform a Salute Properly: Step-by-Step Military Guide & Etiquette

Highest Grossing Movie of All Time: Avatar Box Office Record & Analysis (2025)

1916 Standing Liberty Quarter: First-Year Type 1 Value Guide & Collector Essentials

What is Blood Made Of? 4 Key Components & Functions Explained

How Many Ounces in 2 Quarts? Exact Conversion Guide (US & UK)

Why Do I Feel So Weak? Physical & Emotional Causes + Science-Backed Solutions

Low Water Pressure in Home: DIY Fixes, Causes & When to Call a Pro (Complete Guide)

How to Reset Samsung Washing Machine: Step-by-Step Guide & Troubleshooting

Vitamin B Complex Benefits: Science-Backed Health Impacts & Usage Guide

Frozen Shoulder Causes: Hidden Triggers Doctors Miss & Prevention Tips (Evidence-Based)

Top Foods That Strengthen Immune System: Science-Backed Guide & Practical Tips

How to Change PS5 Background: Step-by-Step Custom Wallpaper Guide (2025)

Baking Chicken Tenders at 350°F: Exact Times for Juicy & Safe Results

Crabs Disease Explained: Symptoms, Transmission & Effective Treatment Guide

How to Make Starbucks Pink Drink at Home: Exact Copycat Recipe That Tastes Better & Saves Money

Perfect Chocolate Chip Cookie in a Mug Recipe: Easy 5-Minute Dessert (Tested 47 Times)

Different Types of Vagina: A Real Guide to Normal Vulva Variations & Diversity

Step-by-Step VA Home Loan Application Guide: Avoid Common Pitfalls & Save Money

How Big Is Denver Airport? Size Facts, Comparisons & Travel Tips

Atomic Radius Trends Explained: Periodic Table Patterns, Exceptions & Applications

Rachael Ray Dog Food Review: Is Nutrish Actually Good for Your Dog? (2023 Analysis)

What Are Natural Fuels? Types, Examples & Environmental Impact Explained

Hernia Mesh Surgery Recovery: Unfiltered Timeline, Risks & What to Expect

Proven Acne Scar Treatments: What Actually Works for Pimples and Scar Prevention

Best Coffee in St Louis: Top Local Picks & Expert Guide (2025)

Vitamin D2 vs D3: Key Differences, Effectiveness & Which to Choose (2024 Guide)

Trump Executive Order 13781 Agency Restructuring: Implementation Failures, Costs & Lasting Impacts (2017-2020)

Benjamin Harrison: The 23rd US President's Legacy, Achievements & Impact (1889-1893)

What is Chattel Slavery: Definition, History & Modern Impact

Appendicitis Self-Check: Where to Press + Critical Symptoms & ER Protocols