Skip to content

Instantly share code, notes, and snippets.

@wolph
Created March 9, 2014 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wolph/9450781 to your computer and use it in GitHub Desktop.
Save wolph/9450781 to your computer and use it in GitHub Desktop.
Script to automatically convert directories to sparse images on OS X. Since I have noticed a pretty obvious slowdown in OS X when having lots (many millions) of files on the filesystem, this has given me quite a significant speedup.
#!/bin/bash -e
function image_all(){
echo "Processing $1"
test -d "$1" || return 1
cd "$1"
for i in *; do
if [ "$i" == "utils" ]; then
continue
fi
image="$i.sparseimage"
if [ -d "$i" ] && [ ! -f "$image" ]; then
echo "Creating $image from $i"
hdiutil create -size 1G -format UDSP -srcfolder "$i" -volname "$i" "$i"
echo "Removing $i"
rm -rf "$i"
else
echo "Skipping $i"
fi
done
}
image_all ~/workspace/
image_all ~/envs/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment