A built-in command-line tool is the fsck command. There’s a lot of self-repair capability built into the OS, and this lets you get to it relatively easily. Check out this post on the Apple forums, “Resolve startup issues and perform disk maintenance with Disk Utility and fsck”, which explains how to use it.
Applejack is a deep system cleanup tool that is also run at the command-line. This is not for the faint of heart, nor is this Aperture-specific. But if your whole system feels slow, and you want to get your Unix geek hat on, check it out at applejack.sourceforge.net