Sponsors

Apple Store

Visit the official Apple Store to buy a Mac online. Free shipping!



Editors' Picks


Comments

Contact Us

Search

Top Posts

Categories

Recent Posts

Our Feeds


Command line disk usage utilities df and du

Getting disk usage information on a Mac is often gathered by selecting a file, directory, or hard drive and hitting Command-I for Get Info, then appears a nice GUI interface with extended information about the selected object including disk usage. Command-I isn’t the only way to get disk info however, with the command line there are two useful utilities to gather this data that you should know; df and du. The following is a brief explanation of each command and how you can use them:

df - displays disk usage information based on file system (ie: entire drives, attached media, etc)

At the command prompt, type:
df -h
The -h flag is for ‘human readable form’ meaning return results in the familiar megabyte/gigabyte format. You should see something like this:

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/disk0s2 74G 52G 22G 70% /

In this case, /dev/disk0s2 is the main hard disk, and 70% of it is in use.

du - displays disk usage information for each file and directory (ie: home directories, folders, etc)

At the command prompt type:
du -sh ~
The -s flag is for a summary, and once again the -h flag is for ‘human readable form’, the ~ is your home directory. You should see something like this:
$ du -sh ~
26G /Users/MacUser

This users home directory takes up 26gb of space!

Another example, type du -sh * at the terminal. The * wildcard will cover all files in your home directory or whatever directory you are currently in, by default the Terminal will launch with your home directory as the pwd (present working directory).

$ du -sh *
32M Desktop
217M Documents
531M Downloads
12G Library
5.2G Movies
2.1G Music
1.5G Pictures
8.0k Public
36k Sites

As you can see, the * allows for a breakdown of the space taken up by which directory. This can be extremely useful when trying to clear up disk space if you don’t know what is hogging all the room.

Digg!


Social bookmarks:


Comments:

Comments: 3

Comment from lar3ry
Time: March 20, 2007, 7:52 am

The DU utility is good for finding out where your disk space is being wasted. Use something like:

du -k * | sort -n

This will show the usage (in 1-K units) of all the files/directories in the current directory, which will be piped to the “sort” utility, using a numeric comparison on the first field (the size). Thus, your largest files/directories will be the last ones listed.

Note that while the -h option is useful for seeing “human readable” sizes, sort isn’t smart enough to realize that “256M” is larger than 816K. [smile]

Comment from Darrell
Time: March 20, 2007, 2:00 pm

I never knew about du, good info to know. And thanks lar3ry for the extended info on du

Comment from Khurt Williams
Time: March 20, 2007, 7:44 pm

Try

du -ck * | sort -rn | head -11

Write a comment





March 20th, 2007