Treesize and durep

Sysadmins need good tools to figure out where file space is being used up. For instance recently I had a user report to me that her entire hard drive was full, but she wasn’t sure why since she really hadn’t added anything to her machine. Now I can easily do a right click on her hard drive and get info to see that the hard drive is, indeed, full, but it doesn’t narrow that dow for me. I clicked on her user profile to see that it was using less than 20% of the total hard drive space. So where did all of her free space go? This is where you need a tool.

For Windows users there is a great tool called treesize. Treesize is a free program that can be run directly from the exe, so if you have a full machine you can run it off of a USB stick. It represents everything graphically and it really helps find that secret stash of movie files the user forgot about. You can see from my windows machine that the biggest offender is the WINDOWS folder.

picture-12

So what about Linux/Unix/Mac. Built into all of these OS is a command line tool called du. Launch the terminal and you will see how it works. Du allows you to see how much space a folder is taking up. Lets see a common output of du on a mac in the /Users folder

bash-3.2# du -h -d 2
4.0K ./mrosedale/.cups
304K ./mrosedale/.fontconfig
8.0K ./mrosedale/.ssh
1.8G ./mrosedale/.Trash
5.5G ./mrosedale/Desktop
5.7G ./mrosedale/Desktop download
45G ./mrosedale/Documents
1.5G ./mrosedale/Downloads
620M ./mrosedale/Library
0B ./mrosedale/Movies
3.2G ./mrosedale/Music
1.1G ./mrosedale/Pictures
0B ./mrosedale/Public
40K ./mrosedale/Sites
64G ./mrosedale
0B ./Shared/Library
12K ./Shared/Microsoft
4.0K ./Shared/SC Info
16K ./Shared
64G .

-h is for human readable and -d 2 is for 2 levels in (so you see ./mrosedale/.cups is two levels in from the working directory /Users. In Linux/Unix you can chain commands together. If you want to chain the output of the du command to another command you simply add a pipe (|). So lets say that we want to see only those entries that are in G.

bash-3.2# du -h -d 2 | grep G
1.8G ./mrosedale/.Trash
5.5G ./mrosedale/Desktop
5.7G ./mrosedale/Desktop download
45G ./mrosedale/Documents
1.5G ./mrosedale/Downloads
3.2G ./mrosedale/Music
1.1G ./mrosedale/Pictures
64G ./mrosedale
64G .

Grep takes the output of du and filters it by G and so we see the results. Grep is case sensitive so if we had wanted both g and G we would need to add the -i option to grep. The command would have looked like this du -h -d 2 | grep -i g. In the case of my user I started at the root directory (/) and ran the command much like this until I figured out where the offending directory was. It ended up being a log file that was returning endless amounts of useless data.

One other helpful command is the durep command. This will usually need to be installed. In Ubuntu you simply need to run aptitude install durep.

root@m-ubuntu-vm:/# durep -td=1
[ / 3.2G (5 files, 19 dirs) ]
1.7G [############### ] 53.09% usr/
512.2M [#### ] 15.57% proc/
291.7M [## ] 8.87% var/
267.9M [## ] 8.14% lib/
253.1M [## ] 7.69% home/
161.5M [# ] 4.91% sys/
36.3M [ ] 1.10% boot/
7.4M [ ] 0.23% etc/
6.5M [ ] 0.20% sbin/
4.9M [ ] 0.15% bin/
2.0M [ ] 0.06% dev/

In this case -td is the same as -d on du. This tool is even better because now it adds the graph and neatly sorts the information for you. I use this tool on my file servers where I need to monitor user directories. One more useful tool in Linux/Unix is that you can redirect output to a file. So if I wanted the output of this program redirected so I could look at it later or compare it I would do:

root@m-ubuntu-vm:/# durep -td=1 > output
root@m-ubuntu-vm:/# cat output
[ / 3.2G (7 files, 19 dirs) ]
1.7G [############### ] 53.09% usr/
512.2M [#### ] 15.57% proc/
291.7M [## ] 8.87% var/
267.9M [## ] 8.14% lib/
253.1M [## ] 7.69% home/
161.5M [# ] 4.91% sys/
36.3M [ ] 1.10% boot/
7.4M [ ] 0.23% etc/
6.5M [ ] 0.20% sbin/
4.9M [ ] 0.15% bin/
2.0M [ ] 0.06% dev/
14.3K [ ] 0.00% tmp/
11.7K [ ] 0.00% root/

Cat simply prints everything that is in the file that we created with the first command.

So there you have it. 3 tools of the trade to hunt down where all of that file space is going. Got any more tips of the trade for file space issues?

Advertisements
Explore posts in the same categories: IT, Linux, Tech Questions, windows

7 Comments on “Treesize and durep”

  1. bfpower Says:

    Does treesize work on Server 2003? I would love to be able to chart all at one time which users are the heavy hitters when it comes to home drive space on the network.

  2. mrosedale Says:

    I just tested it on server 2008 and it worked fine. I would assume that it will work fine on 2003, though they don’t specifically say so on their site. The bigger question I would be interested in is how to automate the process šŸ™‚ I know how to on Linux.

  3. mrosedale Says:

    It seems that I may have missed a tool on the Linux side that is a lot closer to Treesize. http://www.marzocca.net/linux/baobab.html

    Baobab is a graphical tool to do what durep does in the terminal. I still stand by durep if you want automation as it would be much easier to set a cron job that sends an email than it would be in Baobob, but this tool looks helpful.

  4. Martinix Says:

    treesize works on w2k3 as well.

  5. mrosedale Says:

    Thanks for that Martinix, I figured it did, but never got around to confirming that.

  6. mascarnhas Says:

    I’ve used Report and although its great, I’ve had better luck with WheresTheFreeSpace. It is Modeled after a PC application that is very popular called Treesize (but its for Mac).

  7. Klaus Says:

    Hey There. I found your blog using msn. This
    is a really well written article. I will be sure to bookmark it and come back to read more of your useful info.
    Thanks for the post. I will certainly return.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: