33

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
    Jan 21, 2014 at 17:45
  • ^ see the second link.
    – l'L'l
    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
    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 May 29, 2020 at 13:23

7 Answers 7

23

GrandPerspective can create a Treemap:

GrandPerspective screenshot

30

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)

6
  • not include folder 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
    Apr 15, 2021 at 4:31
  • du: illegal option -- O
    – Anthony
    Jan 6, 2022 at 23:12
  • @Anthony, Use du -sh -- …. The -- tells it that there are no more option flags. 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"). Aug 5, 2022 at 12:40
16

You can use spotlight as well:

mdfind 'kMDItemFSSize > 2000000000'

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

2
2

I've had success using:

Disk Inventory X (free download)

enter image description here

It's like WinDirStat was on Windows.

2
  • 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é 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
    Oct 8, 2020 at 14:05
2

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.
1

OmniDiskSweeper

shows you the files on your drive, largest to smallest

great free tool

-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 .