Linux.com

Feature

Disk usage analysis and cleanup tools

By Mayank Sharma on February 01, 2006 (8:00:00 AM)

Share    Print    Comments   

Most of us use our hard disks like closets, stuffing in files and then forgetting about them. But no matter how big a disk you have, it's going to run out of free space one day, and running out of disk space during an OpenOffice.org install or a system update could hurt you badly. Keeping an eye on disk usage doesn't take much time or effort. Here are some tips and tools.

Some distributions set up cron jobs that warn you when disk usage exceeds a certain percentage. But when your usage gets flagged as high, it's deciding what goes and what stays that takes time. Finding the right file or folder to get rid of can be a chore if you have a huge disk. But don't panic. Among all that clutter, you've got some simple tools to bring order to chaos.

The CLI way

The df utility displays the disk space usage on all mounted filesystems. The -T option prints the filesystem type as well. By default, df measures the size in 1K blocks, which could be a little difficult for a desktop user to decipher. Use the -h option to get more understandable output:

$ df -h -T
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/hda6     ext3     20G  9.3G  9.1G  51% /
/dev/hda7 reiserfs     13G  2.1G   11G  17% /mnt/suse
/dev/sda1     vfat    241M  152M   90M  63% /media/usbdisk

You can use the du command to determine which files or directories need to be deleted -- or at least trimmed. A simple du will print usage for the present working directory and its subdirectories, along with the size of each directory.

If you want the size of an particular directory, specify it with du directoryname . For instance, du -h /home/bodhi/podcasts will print the size of the podcasts directory in a more readable format than the kilobytes used by default. The -c option prints the grand total size of the directory at the end. The -a option also displays the file names along with directories and can be of use when you want to see a list of files in a particular directory. The -s option will display a summary, without showing all of the subdirectories.

Running du -ch | grep total prints just one line with the total size of the directory. If there's a particular type of file that you would like to be excluded while calculating a directory's usage, specify it with the --exclude=type option. Here we'll check the disk usage of the current directory, and display all file names with their disk usage, and then sort them numerically using the sort utility:

$ du -ah | sort -n
4.2M    ./eweek.10.28.05.mp3
4.5M    ./LQ-Podcast-101105.mp3
4.8M    ./LQ-Podcast-110905.mp3
19M     ./LQRadio-Episode3.mp3
20M     ./LQRadio-Searls.mp3
36M     ./LQRadio-HiserAndAdelstein.mp3
197M    .

The KDE way

Depending on how your system is set up, command-line utilities might not work well for you. Scrolling through a long list of directories can be tedious. That's where GUI usage analysis tools shine.

KDirStat is a directory statistics utility for KDE, though it will run outside of KDE as long as you have the right libraries installed. If you don't already have it, download the source tarball and build it yourself. On startup it asks you to select a directory, then scans the directory while a Pac-Man animation moves about in the Toolbar area.

Once the scan is complete, the KDirStat screen splits into a two-paned display, with the top showing the contents of the directory and its usage both graphically and in percentage. The loose files are neatly tucked under the Files item. All items display their "Last Change" date, along with their size. All directories and subdirectories show the number of items and files they have inside of them, the number of subdirectories that they contain, and the total size in human readable format.

KDirStat in use
KDirStat in use - click to enlarge

The Treemap view in the bottom half of the screen summarizes the complete directory view as a series of colored squares, with the size of the square reflecting the size of the file. It is useful when trying to locate large files embedded deep within several subdirectories. Clicking on a file or directory in either view selects it in the other as well. You can also open files directly from the KDirStat interface if you're not quite sure what they contain.

Once you have located a file or directory that you can let go of, use one of the various KDirStat's predefined cleanup actions. You can either delete the resource permanently, move it to the trash, or compress it into a bzipped tar archive. You can edit KDirStat's actions if you want to, or to define your own cleanup actions. You also have the option of sending an email to the owner of that file or directory, which may come in handy for admins.

The GNOME way

Baobab does for GNOME users what KDirStat does for KDE users -- search and destroy. Like KDirStat, Baobab can be used with other desktops and window managers as well. If it's not already installed on your system, find a package for your distro or download the tarball and install it.

On startup Baobab displays the total filesystem usage and capacity. You can scan all the filesystems, a selected directory, or a remote filesystem from the Actions menu. Baobab prints the directory tree as soon as it starts scanning. Alternatively, you can also enter baobab path-to-directory at the command line.

Baobab with graphic map
Baobab with graphic map - click to enlarge

If you select a particular folder, the context menu will display three option. "Open" will launch Nautilus and display the contents of the folder. "List all files in folder" will display the contents of the folder under the "File search" tab. "Folder graphical map" will display a graphical treemap of the selected folder. Since the treemaps open in a separate window, you can open treemaps of multiple folders at the same time.

To use Baobab to search for files, go to Actions -> Search for a file. Once you specify the name of the file you want to look up (Baobab supports * and ? wildcards) and the directory to look into, Baobab displays the results under the File Search tab. To delete a file or directory, select it, bring up the context menu, and choose Delete to move it to Trash.

Conclusion

The CLI utilities, du and df, when combined with dd to copy and convert files, can be handy for administers to write disk usage and backup scripts. But desktop users are probably better off using the graphical utilities. KDirStat and Baobab have similar functions, but has better deletion features.

Share    Print    Comments   

Comments

on Disk usage analysis and cleanup tools

Note: Comments are owned by the poster. We are not responsible for their content.

Monitoring disk space..

Posted by: Fletch on February 02, 2006 12:34 AM
I merely use Gkrellm, as it's indicators give me a good idea of the diskspace on my system, not to mention temperatures, network traffic, process load, etc. Plus, it has such a small footprint that it seems to be a better fit. KDiskfree is what I could use that gives me similar disk usage. I am suprised, however at the mentioned KDE method of viewing usage, as this used to be available within Konqueror, but I don't see that option there this time. Oh well.

Haz

#

What about just

Posted by: Anonymous Coward on February 02, 2006 09:35 AM
deleting some of the porn!

#

DiskView for Windows

Posted by: Anonymous Coward on February 04, 2006 12:07 AM
I use DiskView <a href="http://www.diskview.com/" title="diskview.com">http://www.diskview.com/</a diskview.com> on Windows. It nicely integrates with Windows Explorer and shows disk health and temperature in addition to the disk usage.

#

Re:DiskView for Windows

Posted by: Anonymous Coward on February 08, 2006 08:32 PM
if you are using not only Windoze, but even Windoze Exploder you have much bigger problems than disk usage...

#

find ?

Posted by: Anonymous Coward on February 02, 2006 03:10 AM
Why not just use find? find . -size +1M to find all files recursively below current directory bigger than 1 Meg.

#

Try TkDu

Posted by: Anonymous Coward on February 02, 2006 10:43 AM
<a href="http://unpythonic.net/jeff/tkdu/" title="unpythonic.net">http://unpythonic.net/jeff/tkdu/</a unpythonic.net>

#

Filelight

Posted by: Anonymous Coward on February 02, 2006 02:27 PM
I just discovered <a href="http://www.methylblue.com/filelight/" title="methylblue.com">Filelight</a methylblue.com> here a few days ago and felt in love with it. It basically does the same thing that those two graphical utilities does, but IMHO it does it on a much more intuitive way.

Filelight draw pie-charts describing your disk usage and you can browse it by clicking on the slices. Middle clicks will open Konqi windows showing the content of that directory.

It is certainly a nice tool to have on your utilities belt.

#

Also not a bad help

Posted by: Anonymous Coward on February 02, 2006 05:29 PM
I think the program jDiskReport is also one of the good helping tools maybe somebody would like to give it a trie:

<a href="http://www.jgoodies.com/freeware/jdiskreport/" title="jgoodies.com">http://www.jgoodies.com/freeware/jdiskreport/</a jgoodies.com>

#

konqueror

Posted by: Anonymous Coward on February 02, 2006 07:39 PM
The easiest way is missing: konqueror!

View -> View Mode -> Filesize View

#

not only disk usage, also cleanup

Posted by: Anonymous Coward on February 02, 2006 11:52 PM
what you need for cleanup: kleansweep

<a href="http://de.kde-apps.org/content/show.php?content=28631" title="kde-apps.org">http://de.kde-apps.org/content/show.php?content=2<nobr>8<wbr></nobr> 631</a kde-apps.org>

#

Those GUI applications

Posted by: Anonymous Coward on February 03, 2006 02:29 AM
Hello

I think the screenshots of those 2 GUI applications look silly and confusing. They dont seem like useful applications that can give good overview.

It just look like a mess.

#

Or use gdmap

Posted by: Anonymous Coward on February 03, 2006 04:06 AM
for those not using KDE, gdmap has the same colored squares interface as shown in the picture above. Get it here: <a href="http://gdmap.sourceforge.net/" title="sourceforge.net">http://gdmap.sourceforge.net/</a sourceforge.net>

#

dispus.pl

Posted by: Anonymous Coward on February 03, 2006 09:28 AM
Guys, so simple, so fast, so great !
dispus ("display usage") it´s a PERL script that´s work fantastic ! Only "copy&paste" to a script in your system (Linux, Solaris, HPUX,<nobr> <wbr></nobr>...) and go !
Ref: <a href="http://www.unixreview.com/documents/s=8967/ur0311e/ur0311e_script.htm" title="unixreview.com">http://www.unixreview.com/documents/s=8967/ur0311<nobr>e<wbr></nobr> /ur0311e_script.htm</a unixreview.com>
Good work,

Nelmar Alvarenga

#

Re:dispus.pl

Posted by: Anonymous Coward on January 06, 2007 03:44 PM
It's not that fast when you have a lot of directories. I am looking for a tool that will save off this information so we can see which directories are growing over time. Any idea?

#

tools

Posted by: Anonymous Coward on March 20, 2007 04:54 PM
great site, and good trick<nobr> <wbr></nobr>;)

for those in favour of the graphical interfaces, its all nice and well but when you use linux you gotta know cli, or else you are missing out on all of the fun, you can compare it with have sex with (grafical) or without (cli) a rubber on !

#

ytree

Posted by: Administrator on February 02, 2006 05:21 AM

This is a situation where <a href="http://www.han.de/~werner/ytree.html" title="www.han.de">ytree</a www.han.de> shines.
Ytree is a UNIX-based replication of the old DOS-based Xtree (and the short-lived Xtree for Unix), the simpler but workable predecessor to XtreePro and XtreeGold.


In ytree, seeing what files are taking up all the room (among the directories you've logged, so you don't have to wade through large but necessary files) is a matter of setting the sort-order to sort by size (s-s, or s-o-s if you prefer the big ones sorted to the top) while within the file window. Then hit 's' within the directory window to invoke sort-all, where the logged files are displayed as if they were all stored within a single flat directory.

To get rid of the obvious rubbish, tag (with 't') all the files you no longer want. Then, with a single control-D, and confirmation, all of the tagged files are deleted.

Not sure if a given file is needed? Have a quick peek inside it with 'v' (view).



Ytree's tag-and-bag method works on filenames containing spaces and shell-metacharacters without special handling, which makes it much more convenient than cleanup at the command-line.



About the only XtreeGold capabilities I really miss in ytree for file cleanups are the dual-pane view and the branch-grafting function, but Midnight Commander (mc, part of most distros I use) has those, so I keep both programs on systems I own or admin.

#

an easier way?

Posted by: Administrator on February 02, 2006 08:25 AM
instead of doing a
<tt>du -ch | grep Total</tt>
why not just do a
<tt>du -sh</tt>
, should give you the same output

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya