List directories and their sizes in Mac OS X command line

26

6

Possible Duplicate:
How do I get the size of a Linux or Mac OS X directory from the command-line?

I am in a folder, and I want a list of all the sub-directories and their total sizes.

I dont' want it to list all the sub-directories and files in a recursive manner, just the top level directories and the total size it uses on my drive.

How can I do this?

user27449

Posted 2013-01-27T16:25:45.470

Reputation: 5 104

Question was closed 2013-01-27T17:11:00.770

1@slhck I'm doing "research effort" right now just came across this page as most prominent Google hit. What does that say about your comment? – geotheory – 2015-02-01T13:42:43.347

@geotheory It's great that you searched first and found a helpful answer, and don't need to ask the same question (yet) again. Not sure what you're getting at? Matteo asked for a possible downvote reason, and I explained the most likely one. One reason we ask for research effort is to prevent duplicate questions from happening, and if this one is ranked highly on Google, even better. – slhck – 2015-02-01T15:10:55.990

1Hi. I'm not commenting on down-voting. It's more a generic observation (probably belonging in meta) that I've solved innumerable problems using SO/SE pages that feature comments to the effect of 'should've checked google'.. – geotheory – 2015-02-01T15:25:30.810

for mac users, I just want to recommend this free software called Disk Inventory X. download it here http://www.derlien.com/ it's simple to use for mac osx

– Nimitack – 2018-01-06T23:06:21.757

Why the down votes? – Matteo – 2013-01-27T17:09:46.483

@Matteo I'd say that this question does not show research effort. In fact, the Related list shows the question which is essentially a duplicate, which means the OP should have seen it when they were searching for an answer to their question before they posted it. – slhck – 2013-01-27T17:14:15.647

@slhck I agree but I was more hinting that a down vote should be commented (or the question flagged). – Matteo – 2013-01-27T21:01:35.510

@slhck And actually the question is not an exact duplicate. In the possible duplicate nobody speaks of excluding files (du -hs * does not differentiate ...) – Matteo – 2013-01-27T21:03:02.030

Answers

63

With du you can compute the size of a directory:

du -hs dir

if you have only directories you can just (-h will return a human readable units, -s will not recurse)

du -hs *

if in the folder you have contains files and folders:

find . -maxdepth 1 -mindepth 1 -type d -exec du -hs {} \;

find will list all the directories (-type d) in the current folder (-mindepth 1 -maxdepth 1) and execute du on them.

Matteo

Posted 2013-01-27T16:25:45.470

Reputation: 6 553

FYI - As is this command generates a warning: find: warning: you have specified the -mindepth option after a non-option argument -type, but options are not positional (-mindepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.

Solution: find . -maxdepth 1 -mindepth 1 -type d -exec du -hs {} \; – Bisonbleu – 2019-07-10T14:27:31.727

@Bisonbleu Thanks, I edited the answer. BTW I don't get any warning on High Sierra. – Matteo – 2019-07-20T15:54:34.580

For the record, I'm on Mojave 10.14.5 – Bisonbleu – 2019-07-21T16:30:12.590

0

Try typing the following from inside the directory you're interested in

du

Works on unix so should work on mac

SwiftD

Posted 2013-01-27T16:25:45.470

Reputation: 399

Yes but it lists all the files and folders seperately, I just want the folder sizes (totals). – user27449 – 2013-01-27T18:52:28.917