Tag Archives: dmg

MacOSX command line tricks

Here's a list of MacOSX commands I had to search for all over the internet because I needed to use them lately and I'm sure I'm going to forget since I'm not a big OSX user. So here they are for when I'll need them again ... 🙂

In linux when you want to know which ports are opened and what applications listen on those ports you use netstat -lnp
In MacOSX you get the listening ports with this:

  1.  

Want to see what system call am application is making use strace, for MacOSX thats:

  1.  

Here's how to install an application that comes packaged in a .dmg:

  1.  

uninstall a package

  1. span style="color: #ff0000;">'\n' '\0'

pidof required by some mysql scripts

  1. span style="color: #ff0000;">"{if (\$5==\"$1\") print \$1}";
  2.  

remount with noatime

  1.  

More to come ...

How to create a dmg image

In a previous post I showed you how to mount a .dmg image from the command line.

Have you ever wondered how you can create such an image? Continue reading if you want to know.

Let's assume you want to create an image with a size of 10Mb that is formatted with a case sensitive HFS+ filesystem, with a Volume name Test stored in a file with the name Test.dmg.
Here is the command line you have to type in the shell:

  1. span style="color: #ff0000;">"Case-sensitive HFS+"

If you want to put files on it you have to attach it first:

  1.  

Or you could just add -attach to the list of parameters of the hdiutil command and it will also attach it after it creates it:

  1. span style="color: #ff0000;">"Case-sensitive HFS+"

Now you can copy your files to /Volumes/Test and when you're done you can detach the image in case you want to transfer/copy/move it:

  1.  

If you want a quick way to create an image from the contents of a folder you can use something like this:

  1. hdiutil create -fs "Case-sensitive HFS+"

With that you can also specify a format for the image like compressed or read-only images.
Note that in this case I have not used that -size specifier anymore because the image will be as large as the contents of the source folder.

hdutil create --help for more details about image formats encryption and other goodies 🙂

Mount .dmg images from command line

DMG images are the way that a lot of MacOSX binary packages are distributed.  They are somehow like virtual hard disk images or .iso images that you can just mount with a simple double click if you have access to the gui.

But how do you do that from the command line?

quick answer:

  1.  

and the image should now be mounted somewhere in /Volumes

The hdiutil is a tool used to manipulate such disk images. It can do a lot more then just mount the images. It can even burn  them to an optical media, convert them to an iso  and some other formats , even compress them using gzip or bzip2 .