Extract files from ISO images from a command line script on Mac OS X

I recently ran into a situation where I needed to extract files from ISO images in bulk. Unlike Windows where one has so many popular and free applications for this task, I just made up a multi-line process for the same on OS X.

I used the hdiutil to mount and unmount the ISO file and a simple cp to extract files as follows…

for m in *.iso
do
	if [ "$m" = "*.iso" ]; then
		break
	else
		echo -e "\nFound $m"
		dd=`hdiutil attach "$m" | cut -f3`
		echo -e "\nFound ${m%%.*} - $dd"
		cp -a "$dd"/ .
		if [ $? -ne 0 ]; then
			exit 10
		else
			hdiutil detach "$dd"
			rm -rf "$m"
		fi
	fi
done

Just in case…this is a bash script snippet. The actual script is longer and does some more work, but, this should give a fair idea as to how one can automate the extraction of files from ISO images.

6 thoughts on “Extract files from ISO images from a command line script on Mac OS X

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s