42

I need to free up space on my Mac and know there are a ton of hidden files that are eating up space (Logic for example downloads a lot of instruments... somewhere).

Is there any way I can create an interactive (or non-interactive) treemap of my hard drive?

Here is an example of a treemap from Wikipedia

Graphical representation of a treemap

5
  • @l'L'l Not quite a duplicate — most of those solutions included the accepted answer don't produce Treemaps.
    – grg
    Commented Jan 21, 2014 at 17:45
  • ^ see the second link.
    – l'L'l
    Commented Jan 21, 2014 at 17:46
  • However, the answers to both questions contain all the recent tree map type utilities that are in common use. What about your situation makes you think "tons of hidden files" are in play? Finder will show you folder sizes quite easily and you can navigate to locate things without needing any extra software.
    – bmike
    Commented Jan 21, 2014 at 18:46
  • To answer bmike, I use Xamarin, and each time I run debut on an app, temp files are created and remain Commented May 29, 2020 at 13:23

8 Answers 8

26

GrandPerspective can create a Treemap:

GrandPerspective Screenshot

35

try

du -sh *  | grep -E "\dG"

to get all files and folders of size 1G and above. (Output will only show once du is done)

EDIT

Bonus variant that includes hidden files: du -sh .[^.]* * | grep -E "\dG"

(Credits for that last asterisk go to @steveb over at superuser.com)

7
  • not include folder Commented Feb 21, 2019 at 13:26
  • 1
    this is awesome - returns files and folders above 1GB in the directory where its run. So we can run it at the top most level and traverse from there
    – Anupam
    Commented Apr 15, 2021 at 4:31
  • 1
    du: illegal option -- O
    – Anthony
    Commented Jan 6, 2022 at 23:12
  • @Anthony, Use du -sh -- …. The -- tells it that there are no more option flags. Commented Aug 5, 2022 at 12:31
  • There's also the problem that the given pattern will miss some things (e.g. ..dots), and filenames with spaces or other strange characters will cause an error. It also misses large files in the current directory. And the grep will get false hits (e.g "My3Grandchildren"). Commented Aug 5, 2022 at 12:40
18

The quickest query or tool would be spotlight:

mdfind 'kMDItemFSSize > 2000000000'

Add or remove zeroes to get fewer or more files under the size limit, respectively.

3
4

I've had success using:

Disk Inventory X (free download)

enter image description here

It's like WinDirStat was on Windows.

3
  • It says that I can't install it because this app is coming from a non identified user: Impossible d'ouvrir "Disk Inventory X" car cette app provient d'un développeur non identifié Commented Oct 8, 2020 at 3:40
  • 1
    @DimitriKopriwa That has happened to me on Mac before. Hold the control key: kb.wisc.edu/helpdesk/page.php?id=25443#manual
    – Ryan
    Commented Oct 8, 2020 at 14:05
  • It seems to not be able to show 100GB of occupied files - despite full disk access
    – IceFire
    Commented Apr 27, 2023 at 19:01
3

Inspired by this answer, I came up with the following to find directories of 1 GB or greater:

du -ht 1G / 2>/dev/null | sort -nr

Breakdown

du -ht 1G / 2>/dev/null | sort -nr
du -h # print sizes in human readable format (e.g., 1K 234M 2G)
     t 1G # exclude entries smaller than 1G
          / # system root directory
            2>/dev/null # redirect stderr (error) output to /dev/null, effectively ignoring it
                        | sort # pipe the output into sort
                               -n # compare according to string numerical value
                                 r # reverse the sort, effectively putting the largest files and directories first

Note that du's -t 1G argument can take other size parameters too (from man du):

-t exclude entries smaller than SIZE if positive, or entries greater than SIZE if negative. The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000). Binary prefixes can be used, too: KiB=K, MiB=M, and so on.

Bear in mind that sort just sorts on the numerical value, not the unit size. You might want to use du's -B option too, to round up to the nearest G, for example.

Another useful du argument might be -a to list files, not just directories.


I use the following binaries on my system:

$ du --version

du (GNU coreutils) 9.0
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjorn Granlund, David MacKenzie, Paul Eggert,
and Jim Meyering.

$ sort --version

sort (GNU coreutils) 9.0
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and Paul Eggert.
2

OmniDiskSweeper

shows you the files on your drive, largest to smallest

great free tool

0

I like Disk Inventory X, it does the job well. But I use also like DiskWave very much (free tool). It is a different tool, but a good complement that I wanted to mention here.

DiskWave screenshot

PS: I am not related in any way with those tools. Many thanks to the authors!

-1

Clean Up Old and Large Files with CleanMyMac 3

The Large & Old Files module in CleanMyMac 3 makes finding space-hoggers on your Mac simple. Just run a scan to see all the files that are taking up the most space — and then clean them up.

enter image description here

How does the Large & Old Files module help me? Everyone has (at one time or another) thrown files into random folders. It’s easy for these files to take up gigabytes of space without even realizing it! CleanMyMac 3’s Large & Old Files scans your entire Mac and brings all these files to the surface. Plus, it lets you see what’s what, based on a file’s size, date last opened, and type.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .