2

I thought the method to find all the folders that have more than 1GB of content would be:

find . -type d -size +1G

where . is the path here and if we want to do it from the root directory:

sudo find / -type d -size +1G

However, nothing was found when I know for sure there are folders that have more than 1GB of content. How is that done?

I also tried Finder and when we press space in the search field, the criterion to add has "File Size" but not "Folder Size".

0

4 Answers 4

4

find doesn't auto-sum so it only looks at the size of each individual item (which in this case would be the directory entry itself). You could do something like

du -h / | grep -E '^[0-9 .]+[GTP]\t'
6
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – nohillside
    Commented Nov 11, 2020 at 10:21
  • by the way, grep'ing for G may not be that great if the requirement changes to larger than 5GB or 15GB Commented Nov 28, 2020 at 3:34
  • This seems the same as apple.stackexchange.com/questions/52993/… with an addition and a subtraction
    – bmike
    Commented Nov 28, 2020 at 3:37
  • @bmike The other question is about files, the one here is about folders.
    – nohillside
    Commented Nov 28, 2020 at 5:55
  • @nopolarity Answers may or may not stay relevant if you change the question. The original question asked for 1G, not for a general solution.
    – nohillside
    Commented Nov 28, 2020 at 6:11
1

I did some research and it seemed one flexible way is:

du -sk */ | awk '$1 > 1048576 { print $2 }'    # larger than 1GB

Note that the original source answer is on Unix Stack Exchange, and the line was

du -sk * | awk '$1 > 10485760 { print $2 }'    # larger than 10GB

and the */ in the first command above is to choose only the directory instead of both files and directories.

I haven't used awk for a while, but the first command above can be used to find all directories that is larger than 10GB (or 20GB, or 50GB), with the size in GB in front, as follows. Just change the size 10 in the command for a different size:

du -sk */ | awk '$1 > (1000 * 1000 * 10) { printf "%.2f   %s\n", $1 / 1000 / 1000, $2 }'

and it can be tweaked for whether it is GB vs GiB accordingly.

0

There is an app named GrandPerspective that will scan your disk and make a color mapping of everything on your disk. It draws different color blocks to represent a file or folder on you hard disk.

There is also an app called Disk Inventory X that will scan your hard drive and make a list of all folders and their sizes. It will also make a color map like GrandPerspective.

0

Combining your attempt and nohillside's answer this should work for you:

sudo find / -type d -exec du -h -s {} \; | grep '[0-9]G'

This is find all directories, sum the size of the files that they contain in a human readable format, and filter them for any lines that contain #G.

Couple caveats:

  • It will give dupes in that if a given directory has more than 1G, then all parent directories will also show in the list.

  • If you want to use this in the root directory you'll have adjust your System Integrity Permissions otherwise you'll get "operation not permitted" errors (even with sudo). To adjust: System Preferences > Security & Privacy > Privacy Tab > Select Full Disk Access > + > Terminal. Reference: https://appletoolbox.com/seeing-error-operation-not-permitted-in-macos-mojave/

1
  • how is this different from @hillside 's answer? but is it true that your answer actually look down into the subdirectories while his answer only look at top level directories? So I think each answer has its advantage. Your answer would find all "qualified" directories but it also does du repeatedly on subdirectories again and again... but it is still somewhat of a hack, do use grep to grep some text... what if the result is TB, then the grep won't work Commented Nov 7, 2020 at 5:34

You must log in to answer this question.

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