Linux disk usage FAQ: How do I show disk usage information on a Unix or Linux system, such as how large a directory is?
The Unix and Linux
du command shows information about "disk usage". Whereas the
df command ("disk free") shows information about Linux filesystems, the
du command shows disk usage information about only the files and directories you specify.
du command example - Linux directory size
I most commonly use the
du command to show Linux directory size, i.e., how large my subdirectories are, including all the files and subdirectories they contain. For example, on the Mac OS X 10.5 system (a Unix system) I'm currently working on, the following
du command example displays the size of each subdirectory under my current directory:
$ du -hs * 60K Burn-an-ISO 1.2M BurnFolders 4.3M CreateAPodcast-1 2.1M CreateAPodcast-2 16M CreateAPodcast-3 2.5M Java-Mac-Jar-Bundler 1.3M Java-on-Mac
With that command, the
-h option of the du command means "human readable" (as in "show me MB and GB"), and the
-s means "only show summary information". It's important to note that this command runs in real time, so for very large directories, it can be slow to return your results.
Show the size of only specified directories
Also, in that
du command example, I knew that my current directory just contained the subdirectories shown, so I just issued that du command followed by the "*" wildcard character. If, in a more complicated world, I just wanted to see the size of a few subdirectories in a directory that contained many more subdirectories, I could just specify the directories of interest, like this:
$ du -hs Dir1 Dir2 Dir3
Linux du command output without the summary flag
As you can see in the following example, if I take the
-s option off my
du command I do indeed get much more detailed output, like this:
$ du -h * 60K Burn-an-ISO 376K BurnFolders/BurnFolders 188K BurnFolders/images 296K BurnFolders/images-orig 1.2M BurnFolders 568K CreateAPodcast-1/CreateAPodcast 1.1M CreateAPodcast-1/images/Original 2.4M CreateAPodcast-1/images 628K CreateAPodcast-1/L2HBackups 28K CreateAPodcast-1/OldCSSFiles 4.3M CreateAPodcast-1 868K CreateAPodcast-2/CreateAPodcast 740K CreateAPodcast-2/images 2.1M CreateAPodcast-2 3.8M CreateAPodcast-3/CreateAPodcast 1.8M CreateAPodcast-3/images/bg-track 720K CreateAPodcast-3/images/copying 668K CreateAPodcast-3/images/external-track 688K CreateAPodcast-3/images/joining 828K CreateAPodcast-3/images/new-track 1.1M CreateAPodcast-3/images/splitting 6.0M CreateAPodcast-3/images 1.2M CreateAPodcast-3/images-orig/bg-track 468K CreateAPodcast-3/images-orig/copying 444K CreateAPodcast-3/images-orig/external-track 464K CreateAPodcast-3/images-orig/joining 556K CreateAPodcast-3/images-orig/new-track 768K CreateAPodcast-3/images-orig/splitting 3.9M CreateAPodcast-3/images-orig 16M CreateAPodcast-3 200K Java-Mac-Jar-Bundler/images 676K Java-Mac-Jar-Bundler/images copy 808K Java-Mac-Jar-Bundler/images-old 328K Java-Mac-Jar-Bundler/java-on-mac 2.5M Java-Mac-Jar-Bundler 308K Java-on-Mac/images 448K Java-on-Mac/java-on-mac 1.3M Java-on-Mac
I'll guess that at least 95% of the time I use the
-s option, because I'm usually tracking down large directories, or I want to see the directory size before I create an archive.
One way to sort the du command output
If you're trying to find large files, sorting the output of the
du command can be one approach. I find that leaving off the
-h option and dealing with "block" output works better for sorting:
$ du * | sort -n
That du/sort command results in this output:
56 CreateAPodcast-1/OldCSSFiles 120 Burn-an-ISO 376 BurnFolders/images 400 Java-Mac-Jar-Bundler/images 592 BurnFolders/images-orig 616 Java-on-Mac/images 656 Java-Mac-Jar-Bundler/java-on-mac 752 BurnFolders/BurnFolders 888 CreateAPodcast-3/images-orig/external-track 896 Java-on-Mac/java-on-mac 928 CreateAPodcast-3/images-orig/joining 936 CreateAPodcast-3/images-orig/copying 1112 CreateAPodcast-3/images-orig/new-track 1136 CreateAPodcast-1/CreateAPodcast 1256 CreateAPodcast-1/L2HBackups 1336 CreateAPodcast-3/images/external-track 1352 Java-Mac-Jar-Bundler/images copy 1376 CreateAPodcast-3/images/joining 1440 CreateAPodcast-3/images/copying 1480 CreateAPodcast-2/images 1536 CreateAPodcast-3/images-orig/splitting 1616 Java-Mac-Jar-Bundler/images-old 1656 CreateAPodcast-3/images/new-track 1736 CreateAPodcast-2/CreateAPodcast 2152 CreateAPodcast-1/images/Original 2304 CreateAPodcast-3/images/splitting 2448 BurnFolders 2528 CreateAPodcast-3/images-orig/bg-track 2704 Java-on-Mac 3776 CreateAPodcast-3/images/bg-track 4208 CreateAPodcast-2 4984 CreateAPodcast-1/images 5056 Java-Mac-Jar-Bundler 7808 CreateAPodcast-3/CreateAPodcast 7944 CreateAPodcast-3/images-orig 8872 CreateAPodcast-1 12248 CreateAPodcast-3/images 32224 CreateAPodcast-3
I may not be very good at working with block size, but I can tell that the
CreateAPodcast-3 folder is far and away the largest subdirectory in my current directory.
More Linux du command information
For more information on the Linux
du command, you can look at the "man page" for
du on your current Unix system, like this:
$ man du
I just added an online version of the Linux du man page here, so you can use that if it's easier.
Also, if you have any Linux
du command examples you'd like to share, please add them to our comments section below.
This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.