[NBLUG/talk] Disk cleanup

Bill Kendrick nbs at sonic.net
Tue Jan 27 16:47:00 PST 2004


On Tue, Jan 27, 2004 at 04:29:25PM -0800, Rick wrote:
> I'm trying to clear up some space on my disk drives.
> The bash find command works great for locating the largest files on the
> drives.
> I would also like to identify directories that contain large numbers of
> files, preferably by adding up all their storage requirements, then
> listing them as done by the find command.  Is there a bash command to
> accomplish this task?

"du -s dirname1 dirname2 dirname3..." gives you summaries of the
size contents of a set of directories.

You can also do "du dirname..." and it will recurse, and show you everything.

You can use that, piped to sort (with the "-n" switch for numeric sorting)
to get you output like this:

  [...]
  7812    ./share/apps/kio_http
  9512    ./share/cache
  10176   ./share/apps
  30724   ./share
  30736   .

...sorted with the largest at the bottom.  (Use "sort -r -n" to get largest
at the top.  "head" and "tail" help here, too)


If you're not going to sort, you can use the "-h" option to "du" for
human-readable values, like:

  [...]
  31M     share
  364k    share/applnk
  [...]


If you happen to be using Debian, I learned a neat trick the other day.
apt-get install debfoster, and then run it.

  debfoster is a wrapper program for apt and dpkg.  When first run, it
  will ask you which of the installed packages you want to keep
  installed.
  
  After that, it maintains a list of packages that you want to have
  installed on your system.  It uses this list to detect packages that
  have been installed only because other packages depended on them.  If
  one of these dependencies changes, debfoster will take notice, and
  ask if you want to remove the old package.
  
  This helps you to maintain a clean Debian install, without old
  (mainly library) packages lying around that aren't used any more.


Careful you don't accidentally uninstall Mozilla or X-Window, tho ;)

-bill!



More information about the talk mailing list