
Apple has posted a Knowledge Base article on Disk Optimization And Fragmentation With Mac OS X, which is worth a read before making any defragging decisions. The article says, in part:
"Files can become 'fragmented' over time as they are changed and saved and as the volume is filled, with different parts of a single file stored in different locations on a volume. The process of collecting file fragments and putting them 'back together' is known as optimization. However, if a failure occurs during optimization, such as power loss, files could become damaged and need to be restored from a backup copy....
You probably won't need to optimize at all if you use Mac OS X. Here's why:
• Hard disk capacity is generally much greater now than a few years ago. With more free space available, the file system doesn't need to fill up every "nook and cranny." Mac OS Extended formatting (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.
• Fragmentation was often caused by continually appending data to existing files, especially with resource forks. With faster hard drives and better caching, as well as the new application packaging format, many applications simply rewrite the entire file each time. Mac OS X 10.3 Panther can also automatically defragment such slow-growing files. This process is sometimes known as "Hot-File-Adaptive-Clustering."
• Aggressive read-ahead and write-behind caching means that minor fragmentation has less effect on perceived system performance.
For these reasons, there is little benefit to defragmenting.
Mac OS X systems use hundreds of thousands of small files, many of which are rarely accessed. Optimizing them can be a major effort for very little practical gain. There is also a chance that one of the files placed in the 'hot band' for rapid reads during system startup might be moved during defragmentation, which would decrease performance.
If your disks are almost full, and you often modify or create large files (such as editing video....), there's a chance the disks could be fragmented. In this case, you might benefit from defragmentation, which can be performed with some third-party disk utilities.
So sayeth Apple.
I beg to differ somewhat.
As noted, adding and deleting files to and from your hard drive will gradually cause the drive to become more and more fragmented. When the OS writes files to the drive, it will look for empty spaces on the hard drive to write data to. If the space is too small to fit the file, it will write part of the data in one area and the remaining to another area. This way less overall disk space is wasted, but drive access will slow down, as the read/write head has to scan multiple parts of the drive to locate and read a file. The more you use your your drive, the more fragmented the data on it will become. Consequently, defragmenting your hard drive from time to time can boost the performance of your computer by putting all of these broken-up pieces into one continuous block with all of the empty space at the end.
Also, while HFS+ is very good at keeping small to medium sized files from getting fragmented, but reportedly less efficient at keeping large files or free space from fragmenting, which is of particular interest to mac-users because the virtual memory swapfile must be contiguous on the disk, so you can actually run out of virtual memory long before you run out of disk space if your free space is fragmented.
For more discussion of defragmentation issues with OS X, see the links in the Appendix below.
Personally, I have been frustrated by the leisurely performance of my Pismo PowerBook since installing OS X 10.4 Tiger last spring. I did an archive and install, which gave me a fresh system, but left the existing 10.3.8 system on the partition until I deleted it. This meant that the Tiger installer had to work around the old system to find space to put the new one, resulting in what I suspected was less than ideal disk optimization.
Recently, I decided to see if I couldn't improve things. First I ran AlSoft Disk Warrior 3 to repair any directory damage (there was some) and replace the old directory with a fresh, new one. I then booted from the ProSoft Drive Genius 1.5.5 CD in order to use the Drive Genius defragmentation module. Because the bare-bones version of OS X on the CD doesn't support screen captures, I couldn't to any screen shots of the fragmentation report, but there was stuff scattered all over the partition in non-contiguous clumps, with a lot of empty space at the top of the partition, presumably vacated by the deleted former system installation.. I figured that a defrag was indeed in order.
The defrag process goes as follows.
The user interface window shows the fragmentation of the volume:
• The yellow portion represents the data has already been defragmented.
• The lavender portion represents file that hasn’t been moved yet.
• The black portion represents the free space.
Here's what the fragmentation map of the 11 GB main partition on my iBook's 20 GB hard drive looked like when I defragged it last spring (in which case I was running Drive Genius while booted from an external FireWire drive and thus could take screenshots). You can read more about that project here:
http://www.macopinion.com/columns/roadwarrior/05/06/07/

Drive Genius gives you a running readout of what is happening as the defragmentation proceeds. Be forewarned that it's not a quick process, especially on an OS X boot volume with all those tens of thousands of tiny files.

In this case on a 78% full 25 GB partition defragmentation took about six hours. I expect that it might go more quickly and on a machine with a faster processor and/or hard drive (mine is a 40 GB, 5400 RPM Toshiba). The process is happy to run in the background, and you can continue working with the computer and even go online if you wish
Here's a finished defrag job (on the iBook):

Worth the effort? You Bet! When I booted back into Tiger from the Pismo's hard drive I was literally astonished at how fast it started up. I'm convinced, and delighted with the more lively performance out of Tiger on the old PowerBook.
Your mileage, as they say, may vary, depending upon how badly your disk data is fragmented. Also, at times my OS X partition on the Pismo has been 80 percent or more filled, a condition that exascerbates defragmentation.
If you do decide to defrag, as always with a major (and in this case somewhat risky of data loss) operation, make sure your data is securely backed-up before proceeding.
Appendix:
For more discussion on OS X disk defragmentation, see:
http://www.macattorney.com/ts.html (includes lots of links)
http://www.macosxhints.com/pollbooth.php?qid=defrag&aid=-1
http://8help.osu.edu/1563.html
And at macFixIt Forums here.
Another Defrag Solution
Another solution for disk defragmenting that I haven't tried, but which looks promising, is iDefrag 1.1.3 � Defragmentation & Optimization for Mac OS X, which is $30.00 demoware.

More info available here:
http://www.coriolis-systems.com/iDefrag-2.php
Charles W. Moore
Tags: Hot Topics ï News ï MooresViews ï

Other Sites
I have to agree with Apple about defraging, but I am glad to follow your recommendation on Disk Warrior which I just ordered an updated Bootable CD-ROM for as well as repairing permissions which I will be doing much more often now that there appears to be somebody who is writing exploits for Mac OS X security holes. I still don’t recommend people buying anti-virus software, but rather update to the latest security updates as this is a more proactive and effective approach as this prevents one from getting infected in the first place a risking losing data. Anti-virus products are just a stop gap measure and definitely not a solution to the underlying security problem only necessary where there is no security at all and thousands of different huge holes as with that other frequently used OS made by Microsoft. Linux also technically has viruses too but how many desktop computers actually get infected - maybe a couple people out of hundreds of thousands of desktops and those are unpatched and several years since they were supported.