41

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

agarza
  • 2,274

8 Answers8

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)

  • not include folder – maxisacoder Feb 21 '19 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 '21 at 04:31
  • 1
    du: illegal option -- O – Anthony Jan 06 '22 at 23:12
  • @Anthony, Use du -sh -- …. The -- tells it that there are no more option flags. – Ray Butterworth Aug 05 '22 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"). – Ray Butterworth Aug 05 '22 at 12:40
  • du -all --max-depth=1 --human-readable | sort --human-numeric-sort >result should eliminate the problems. (Or simply du -a -d 1 | sort -n >result.) – Ray Butterworth Aug 05 '22 at 12:47
26

GrandPerspective can create a Treemap:

GrandPerspective Screenshot

grg
  • 201,078
17

You can use spotlight as well:

mdfind 'kMDItemFSSize > 2000000000'

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

bmike
  • 235,889
4

I've had success using:

Disk Inventory X (free download)

enter image description here

It's like WinDirStat was on Windows.

Ryan
  • 1,303
  • 3
  • 21
  • 36
  • 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é – Dimitri Kopriwa Oct 08 '20 at 03:40
  • 1
    @DimitriKopriwa That has happened to me on Mac before. Hold the control key: https://kb.wisc.edu/helpdesk/page.php?id=25443#manual – Ryan Oct 08 '20 at 14:05
  • It seems to not be able to show 100GB of occupied files - despite full disk access – IceFire Apr 27 '23 at 19:01
2

OmniDiskSweeper

shows you the files on your drive, largest to smallest

great free tool

vitaliytv
  • 121
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.

Erik
  • 273
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!

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

StrawHara
  • 4,893