Skip to content

MacOS du command

The MacOS du command is a powerful tool for analyzing disk usage on your system. By displaying the size of directories and files, you can identify storage-hungry items and manage your disk space effectively. With various options to customize the output format, you can delve deep into specific directories or exclude certain files from the analysis. By understanding the disk usage distribution, you can optimize storage capacity and improve system performance.

du Syntax:

Terminal window
du [option] [parameter]

Options:

OptionDescription
-d, —max-depthLimit the output to a specific depth
-h, —human-readablePrint sizes in human readable format
-s, —summarizeDisplay only a total for each argument

Parameters:

ParameterDescription
directorySpecify the directory to analyze

du Usage:

List Sizes of Files and Directories in the Current Directory

Terminal window
du -sh *

Displays the total sizes of files and directories in the current directory.

Display Sizes of Files and Directories with Human-readable Format

Terminal window
du -h

Displays sizes of files and directories in a human-readable format.

List Sizes of Files and Directories Sorted by Size

Terminal window
du -sh * | sort -h

Lists the sizes of files and directories sorted by size.

Show Sizes of Files and Directories in a Specific Directory

Terminal window
du -h /path/to/directory

Displays sizes of files and directories in a specific directory.

{Questions}

Applications of the du command

  • Checking disk usage of directories and files
  • Identifying large files or directories
  • Monitoring disk usage to prevent running out of disk space
  • Analyzing disk usage to free up storage
  • Verifying if certain files or directories are taking up too much space