Compact sparse disk images via the command line
Mon, Jun 28 2004 at 10:20AM PDT • Contributed by: SOX
Mon, Jun 28 2004 at 10:20AM PDT • Contributed by: SOX
As you may know Sparse Disk Images grow in size as needed automatically when you add files to the image. However they don't shrink in size when you remove files. This limits the utility of them for many purposes, such as maintaining an adaptable sized HFS partion on a USB thumb drive. Well it turns out shrinking those bloated sparse images is not a problem. Just unmount the image if it is mounted. Then pull up a Terminal window and type:
Of course it is a swell idea to make a backup copy of the sparseimage before you compact it, just in case!
hdiutil compact /some_path/your.sparseimage
where /some_path/your.sparseimage is the path and file name of the sparse disk image. This will harmlessly reduce the sparse image down to the minimal size needed to contain the files within it. It does not erase the disk image and you won't lose any files doing this. As a side effect, it is likely the files in the image and the imagefile itself will be defragmented in the process. The process is very fast if the image is mostly empty.
Of course it is a swell idea to make a backup copy of the sparseimage before you compact it, just in case!
•
[25,779 views]
