Macs are pretty imperturbable. There are no real viruses, malware is limited to a Trojan you are fooled into installing yourself, and built-in behind-the-scenes routines in OS X do a lot of the maintenance for you.
But every now and again things still go wrong - the Mac slows down, or an app crashes or worse. It's 'just' a computer, after all.
In my 157th free '5 Tips' page on my own site, mac-nz.com, I covered some things you can do when things do go wrong, so I thought it might be helpful to talk about Mac maintenance here. My online tips are only available on Fridays, but I collate them into a free PDF newsletter called MagBytes that goes out to nearly one-and-a-half thousand people on a private email list on the last Thursday of every month. But you have to ask for it.
I have mentioned switchers here before - one of the common things people ask me when they come across from The Dark Side - PCs - is how do they optimise a Mac's hard drive. That's easy - leaving the Mac on pretty much covers it. As Apple's official advice says, hard disk capacity is generally much greater than a few years ago, so more free space is available and the file system doesn't need to fill up every track.
Mac OS Extended hard drive formatting (aka HFS Plus) avoids reusing space from deleted files as much as possible, to avoid prematurely filling small areas of recently-freed space.
Mac OS X 10.2 and later includes delayed allocation for Mac OS X Extended-formatted volumes. This allows a number of small allocations to be combined into a single large allocation in one area of the disk. Faster hard drives with better caching, as well as the new application packaging format, means many applications simply rewrite the entire file each time rather than appending data to existing files, decreasing fragmentation. From Mac OS X 10.3 'Panther', automatic defragmentation of slow-growing files, or 'Hot-File-Adaptive-Clustering', also prevents fragmentation. This occurs in the background.
Also, newer HD tech has aggressive read-ahead and write-behind caching meaning minor fragmentation has less effect on perceived system performance.
Apart from that, installing items sometimes shows a little end dialogue saying 'Optimising files'; some minor HD optimisation occurs at this juncture.
The short of it is, you don't need to defragment/optimise your Mac's hard drive.
You can, if you insist, properly 'defragment' your HD, for example to gain some slight video performance for heavy video work. But you'll need to get a third-party utility. Drive Genius is a good one; it's US$99 but there's a free trial available which allows some of its functions.
As far as general diagnostics and maintenance goes, Macs automatically run Cron Scripts on older versions of OS X and 'launchd' scripts from Snow Leopard (OS 10.6x) onwards. These self-run in the small hours should you leave your Mac on all night. Developers and others handy with code can use Terminal (it's a Unix interface installed on every Mac, since Unix is already on every Mac). Terminal is in your Applications folder, in turn in the Utilities folder, and it can initiate and take charge of these actions. Some programs like the much-touted MacKeeper (or Onyx or Magician, which unlike MacKeeper are free) let you run them as mere mortals would run them: in interfaces that look intelligible. Which is how I to do it.
If you seriously want to get into Terminal and action initiation, I suggest you start by looking at Paul Annesley's guide, which is mostly Greek to me.
The most I ever do with Terminal is initiate a script someone much more versed in it recommends on one of the Mac faithful websites. In these cases I simply paste it in and press return, as this Bash stuff is dangerous territory and I'd hate to type a command out wrong. But note, though, you can make Terminal look really cool as its Settings tab in Preferences has some really cool options ... Silver Aerogel, yeah.
Anyway, there are more user friendly utilities already on your Mac than Terminal. Disk Utility is a good example. This Apple app has a simple interface (OK, I do mean 'boring') and it's not particularly expressive as to what it can do, either, but I find it indispensable. Booting it up every couple of months and running Repair Disk Permissions with the internal hard drive selected on the left seems to keep everything sweet, rewriting the underlying database (very broadly speaking) of where everything is. I have noticed considerable speedups from doing just this, but don't bother 'Verifying Disk Permissions' as it takes the same length of time to tell you something is wrong, in which case you have to run Repair to fix it anyway. So just run that. Some people reckon Repair Permissions does nothing, but I have noticed the incidence of crashing lessens considerably after running it in many instances, and it often seems to speed up, so I'm in the pro camp. It can also point out a really serious error that needs proper surgery, which is good to know before a hard drive failure.
Repair Disk is greyed out, as repairing the disk that the software sits on would be like a heart surgeon operating on her own heart. She can fix a cut on her finger and maybe even a broken bone, but her own heart? Nope. In Disk Utility, Repair Disk becomes active if another hard drive (or thumb drive, or even a card from a camera) is plugged in. This is your heart surgeon fixing someone else. Then you can do a much more fundamental repair on an external, (non System-running) volume, or completely erase and reformat it.
One of Take Control's excellent range of eBooks is the Macworld Mac Troubleshooting Guide, which thoroughly details a lot of this. That will set you back about NZ$15.50 (it's US$12.95) but it's really good.
There's even a very clever way of booting the Mac up completely as a Unix system and using that to 'fix' OS X, or at least the hard drive partition it sits on. This is the Fix Disk procedure. But I'm not going to go through that here - if you need this and more, check out the Help page on my mac-nz site.