Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: See a quick view of folder-by-folder disk utilization UNIX
In the process of migrating data from the old machine to the new machine, I was surprised to see that my user's Documents folder was 2.0+gb in size. However, the presence of 50+ folders in that directory made it tough to figure out exactly where the problem might lie (doing a Get Info or Inspector window 50 times over gets old, quick).

Time for a command line rescue ... and though this hint works in 10.2 (and probably earlier), it's better in Panther. To see a list of disk space by directory, you first need to cd into the directory you wish to study (Documents, in my case), and then issue this command:
 % du -ksh *
If you're not using Panther, the h on the end won't do anything ... but in Panther, it forces the output into "human readable" mode (KBytes and MBytes). The k option creates 1KB blocks for counting, and the s option creates one output line for each file in the directory. In my case, I saw this (trimmed for length):
% du -ksh *
 18M    848077.tif
135M    Kylie related
786M    Segway video.dvdproj
156K    Servers
  0B    Sound 
528K    Untitled Animation
165M    iChats
 82M    icons
1.2M    infocom
942M    macosxhints
 87M    home_photos_2002
 22M    screens
5.2M    stuff
137M    textures
This made it very easy to identify the suspect "large" directories and either clean them out, trash them, or find room for them on the new machine. I'm sure there are many variations on this theme (comments, anyone?), but this one works quite nicely, especially with the newer version of du in Panther.
    •    
  • Currently 1.71 / 5
  You rated: 1 / 5 (7 votes cast)
 
[18,431 views]  

10.3: See a quick view of folder-by-folder disk utilization | 15 comments | Create New Account
Click here to return to the '10.3: See a quick view of folder-by-folder disk utilization' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: See a quick view of folder-by-folder disk utilization
Authored by: eduo on Oct 25, '03 03:24:43AM

It's even better if you add a piped command for sorting.

du -ks * | sort -rin

That'll sort the listing from highest disk space to lowest, including the totals of disks.

The -h parameters is a nice touch for shorter listings, but this is a better way to find the biggest culprits around. I've been using this for over 6 years and it's one of the commands I use the most when pruning. I took it out because then the sorting loses a little bit of sense.

It's still useful as long as you remember it's sorting alphabetically, which means all "K" will be together, all "M" will be together and all "G" will be together, sorted within their own group.

Lastly, you could do:

du -ks * | sort -rin | head -n 20

To see the top 20 disk hoggers in your directory. I used this a lot when I was working in an ISP 4 years ago to see what users where using up too much disk space..:)

---
Eduo



[ Reply to This | # ]
10.3: See a quick view of folder-by-folder disk utilization
Authored by: eduo on Oct 25, '03 03:49:17AM

That was the geeky response, I feel forced to give also the no-brain comment to this hint.

This is easily doable in the Finder as well, which may be overlooked when we're trying to find new things to do around.

You can do this simply switching to "list" mode and enabling "Calculate all sizes" in the Info Options window (command-J). I have this enabled for list sizes in all Windows, as it's so practical.

You switch to list view, you enable "Calculate Sizes" and you can click on the "Size" column header to sort by that parameter. This is especially useful because you can expand the folders (click on the triangle) and the contents will appear sorted as well, so you could in a single window list your whole home directory, see you have 15GB in your "Movies" folder, expand that in the same window and see that you haven't deleted the iMovie project you did two years ago of your cousin's wedding (can you tell this is a real-life experience?..:)

(BTW, this is one of the beautiful functionalities you may miss if you always use Column View, something I will never get accustomed to, it seems, as it's a view optimized for fast navigation, not fast manipulation of files)

Eduo

PS: It's still a good hint as the text version works in terminal even in remote machines and, coupled with sudo, works as well for every directory in the system, while the paragraph above works only in the local machine.

PS2: I could've posted this hint a long time ago. I still can't realize when something I might've been using for years may be of value to others..:)

---
Eduo



[ Reply to This | # ]
10.3: See a quick view of folder-by-folder disk utilization
Authored by: flunkedflank on Oct 25, '03 04:23:07AM
Even better: use OmniDiskSweeper!

I use the terminal (and the du command especially) quite heavily, but I would highly recommend switching to this GUI equivalent -- saves a lot of repeated typing when running du on different hierarchies. In fact I was going to attempt writing such a thing until I discovered it already existed. There's also WhatSize, which seems the same, but I haven't used it myself yet.

note: I haven't confirmed either in Panther yet!

[ Reply to This | # ]

10.3: See a quick view of folder-by-folder disk utilization
Authored by: shark on Oct 25, '03 11:27:52AM

Wow. I just downloaded the "What Size" application. VERY very impressive. No use for that terminal command when there is a GUI app out like this. I am running Panther and its runs perfect with it. Not to mention the app is freeware. If you haven't tried it you need to. It quickly runs through your entire Home directory and sorts it by Highest file size and then you can click right down through the directories in column view seeing the file sizes as you go.

---
---
Shark



[ Reply to This | # ]
OmniDiskSweeper works OK in 10.3
Authored by: mikerose on Oct 27, '03 12:21:35AM

...much to my delight, as after I installed Panther I found myself a bit short of space. Still works as advertised. Omni did a great job with the basic functionality; I've licensed it for all my servers, as it makes it much easier to find the user who's stashed an entire season (8.3 GB) of Showtime's "Dead Like Me" in their home folder (you know who you are!) and blown out our backup scheme.

Haven't tried WhatSize yet, or the CLI equivalents in the hint, but all sound pretty good. I also find myself going back to FileBuddy from time to time for similar tasks.



[ Reply to This | # ]
10.3: See a quick view of folder-by-folder disk utilization
Authored by: tomem on Oct 25, '03 09:51:00AM

Just open a Finder list view, turn on "calculate sizes" (cmd-j to get the view options), and sort by size. Open up folders as needed to find the culprits. Delete as needed.
Command line - Schamand line. This give a quicker, more flexible, and better organized view.

---
TomEM
Crofton, MD



[ Reply to This | # ]
10.3: See a quick view of folder-by-folder disk utilization
Authored by: kevinv on Oct 25, '03 11:44:05AM

And don't for get to turn back off calculate sizes, it slows your list views and creates a lot of disk accesses (kills your battery on a laptop). That's a whole bunch of clicks, command line seems faster to me, for this particular problem at least.

And the command line can be piped into a text file or csv file for importing into a spreadsheet to create a log of disk growth over time.

The GUI way may look better but it isn't always the solution.



[ Reply to This | # ]
Free Java-based disk usage utility
Authored by: retrovirus on Oct 25, '03 11:49:06AM
JDiskReport is a handy free Java-based program for doing this. It has a straightforward, polished interface for those who don't want to mess around with the command line stuff.

[ Reply to This | # ]
10.3: See a quick view of folder-by-folder disk utilization
Authored by: durin on Oct 25, '03 02:16:20PM

The h option works just fine here in Jaguar. I want Panther, but I need to wait for XPostFacto to use it on my beige g3.

% du -ksh *
8.2M Desktop
.
.
.

---

Go not to the elves for council, they will say both no and yes



[ Reply to This | # ]
10.3: See a quick view of folder-by-folder disk utilization
Authored by: tomem on Oct 25, '03 02:43:31PM

Unlike OS 9, in OS X folder sizes are only calculated when the folder is exposed in an open Finder window. I see no hit to my system from leaving a number of those boxes checked, including at the root level of my disk. I routinely use this approach for disk management, and I monitor my cpu continuously with Menu Meters.

My backup log gives me a good picture of long term useage trends. But you could use cmd-shft-4-spacebar to create a window picture on the desktop. Not sure how one would direct it to a text file however.

I'm not against the command line, but using other third party tools to look at one's disk useage seems silly to me when the Finder does quite well...

---
TomEM
Crofton, MD



[ Reply to This | # ]
10.3: See a quick view of folder-by-folder disk utilization
Authored by: gospodin_david on Oct 25, '03 02:47:46PM

You don't need the k flag; when you use the h, it overrides k.



[ Reply to This | # ]
10.3: See a quick view of folder-by-folder disk utilization
Authored by: inspired_tmu on Oct 25, '03 03:04:13PM

There's also a K Widget that will do this:

http://www.widgetgallery.com/view.php?widget=35776

[ Reply to This | # ]

10.3: See a quick view of folder-by-folder disk utilization
Authored by: Mr. Bappo on Oct 26, '03 11:32:15AM

Or how about What Size?
http://www.apple.com/downloads/macosx/system_disk_utilities/whatsize.html

Mr. Bappo



[ Reply to This | # ]
10.3: See a quick view of folder-by-folder disk utilization
Authored by: kmue on Oct 27, '03 03:26:47AM
Here is my attempt to sort and summarize the du(1) output. It works nicely across platforms.

#!/bin/sh
# sort output of du(1) and format it like GNU's "human readable format"
# and sum it up - km 20030716
#
awk=/usr/bin/awk
du=/usr/bin/du

$du -k $* | sort -rn | $awk '{
  t+=$1;
  if ($1>1024) {
    r=$1%1024; if (r!=0) { sz=($1-r)/1024 } else { sz=$1/1024 };
    print sz"M\t"$2;
  } else {
    print $1"K\t"$2;
  }
} END {
  if (t>1024) {
    r=t%1024; if (r!=0) { sz=(t-r)/1024 } else { sz=t/1024 };
    if (sz>1024) {
      r=sz%1024; if (r!=0) { ssz=(sz-r)/1024 } else { ssz=sz/1024 };
      print "Total: "ssz"G ("sz"M)";
    } else {
      print "Total: "sz"M ("t"K)";
    }
  } else {
    print t"K\tTotal";
  }
}'


[ Reply to This | # ]
infocom
Authored by: Thom on Oct 28, '03 01:16:42PM
1.2M infocom

Nice! I collected all of the original program packages and contents, between Apple ][e and Macintosh. I was overjoyed when frotz came out, and when I got OS X, I could compile the unix/ncurses version and run the stuff without needing a special Mac port. Oh, and my IL license plate is 'INFOCOM'.

I'm a big dork.

[ Reply to This | # ]