• Contact
  • About Me
  • Privacy Policy
DefenceDev
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
DefenceDev
No Result
View All Result
ADVERTISEMENT
Home Linux Tutorials Commands

Check Disk Usage on the Linux with du Command

neo by neo
May 27, 2025
in Commands
0
Check Disk Usage on the Linux with du Command

Check Disk Usage on the Linux with du Command

0
SHARES
8
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

Disk Usage on the Linux

Check Disk Usage on the Linux with du Command is a crucial aspect of maintaining a healthy Linux system. When storage starts to fill up, identifying which files or directories are consuming the most space can save time and prevent disruptions. The du (disk usage) command is an indispensable tool for this purpose, providing detailed insights into disk usage at the file and directory level.

Introduction

The du – disk usage command displays the amount of disk space used by files and directories on Linux systems. By default, it shows the disk usage of each directory and subdirectory within the current directory.

Basic du Syntax

du [OPTION]... [FILE]...

Commonly Used Options

Here are some of the most commonly used options with the du command:

ADVERTISEMENT
  • -a or --all: Includes both files and directories in the output.
  • -h or --human-readable: Displays sizes in human-readable format (e.g., K, M, G).
  • -s or --summarize: Displays only the total for each argument.
  • -c or --total: Displays a grand total of the disk usage found by the other arguments.
  • --max-depth=N: Limits the output to directories (and files) at most N levels deep.
  • -d or --depth=N: Similar to --max-depth=N, shows the total for directories up to N levels deep.
  • --exclude=PATTERN: Excludes files that match the given pattern.

Basic Examples of du command

  • To display the disk usage in a human-readable format:
du -h
  • To display only the total disk usage of the current directory:
du -sh
  • To include all files in the output:
du -ah
  • To limit the depth of the directories shown in the output to two levels:
du --max-depth=2
  • To display a grand total at the end of the output:
du -ch
Output of the du command "du -ch"
Output of the command “du -ch”
  • To exclude files that match a specific pattern:
du --exclude='*.log'
  • Displays disk usage of files and directories and summarize the total size of each argument:
du -skh *

Advanced Usage and Tips

  • Analyzing Large Directories: Combine du with other commands like sort and head to find the largest directories:
du -ah /path/to/directory | sort -rh | head -n 10




  • To see the memory usage of directories within a folder and sort them by size, you can use the du (disk usage) command combined with sort:
du -h --max-depth=1 /path/to/folder | sort -hr

Explanation

  • du -h --max-depth=1 /path/to/folder:
    • du stands for “disk usage.”
    • -h makes the output human-readable (e.g., in K, M, G for kilobytes, megabytes, and gigabytes).
    • --max-depth=1 limits the command to only look at the top-level directories within /path/to/folder.
  • sort -hr:
    • sort sorts the output.
    • -h sorts by human-readable numbers.
    • -r sorts in reverse order (i.e., from largest to smallest).
  • To check the memory usage in the current directory and sort by size:
du -h --max-depth=1 . | sort -hr
Output of the du command "du -h --max-depth=1 . | sort -hr"
Output of the command “du -h –max-depth=1 . | sort -hr”

This command will provide a list of directories and their sizes, sorted from largest to smallest.

Other Examples

A very efficient way to check disk usage is the ncdu application. You can check it at the link.

ADVERTISEMENT

About The Author

neo

See author's posts

ADVERTISEMENT
ADVERTISEMENT
Previous Post

Nextcloud: How to Upgrade Nextcloud via the Web Interface

Next Post

YouTube Channel about Linux Topics

neo

neo

Next Post
YouTube Channel about Linux Topics

YouTube Channel about Linux Topics

Follow Us

  • Trending
  • Comments
  • Latest
MikroTik: Export Configuration in Text File

MikroTik: Export Configuration in Text File

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Immich: Installation on Ubuntu 22.04

Immich: Installation on Ubuntu 22.04

Fortinet FortiGate Upgrade Path Tool

Fortinet FortiGate Upgrade Path Tool

NextCloud: Port Forwarding - Essential Ports for Smooth Functionality

NextCloud: Port Forwarding – Essential Ports for Smooth Functionality and Remote Access

Organizing and Managing Photos with Immich: Features I Use

Organizing and Managing Photos with Immich: Features I Use

Install Ubuntu 22.04 on Oracle VM Virtual Box

Install Ubuntu 22.04 on Oracle VM Virtual Box

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

MikroTik: Check Your Wireless Password

MikroTik: Check Your Wireless Password

ADVERTISEMENT

DefenceDev Tutorials

defencedev Logo

Whether you’re just starting or looking to expand your skills, I hope you find useful information and engaging discussions here. Let me take you through my journey and the goals behind this space!

Follow Us

Browse by Category

  • Blog
  • Cloud
    • Private
  • Linux Tutorials
    • Bash Scripting Tutorials
    • Commands
    • Networking
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Solutions
    • Docker
  • Video Tutorials
    • MikroTik Videos

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

  • Site Map
  • Privacy Policy
  • Facebook Page
  • Disclaimer
  • Contact
  • About Me

© 2025 defencedev.com - All rights reserved.

No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos

© 2025 defencedev.com - All rights reserved.