<< Back to posts

How to Analyze Memory Usage of Folders/Files on your Mac

Posted on January 3, 2023 • Tags: Mac memory

Three ways to view memory usage (i.e. “disk usage”) on your Mac, in descending order of preference.

ncdu (command)

“A disk usage analyzer with an ncurses interface”

Installation

brew install ncdu

Usage

ncdu PATH_TO_FILES

Replace PATH_TO_FILES with the path that you want analyzed. Typically set to ./ (i.e. your current working directory).

Example

gdu-fast-console-disk-usage-analyzer

Reference

Homepage, including download link

Grand Perspective (GUI)

“A small utility application for macOS that graphically shows the disk usage within a file system.”

Installation

brew install --cask grandperspective

Usage

The simplest – just open up the application.

Each box is a file, and the size of the box is the relative size of that file on your disk.

Example

2_5_4-FoldersBujumbura

Reference

Homepage, including download link

du (command)

“The standard Unix/Linux command, used to check the information of disk usage of files and directories”

Installation

None - comes pre-installed on Mac

Usage

du -hs PATH_TO_FILES

The h flag says “display memory in human readable format”, the s flag says “summarize directories as the sum of their files” (rather than printing out each individual file)

Replace PATH_TO_FILES with the path that you want analyzed. Typically set to ./ (i.e. your current working directory).

Example

Print size of every file/folder in the current directory, sorted by size:

du -hs * | sort -hr

Print size of every subdirectory in current directory, sorted by size:

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

Reference

Linux Man Page