Archiving from the command line

Nov 05, '01 12:03:56AM

Contributed by: tomsinclair

Stuffit Deluxe is a great tool for most archiving duties, but not too good if you have a large number of individual file archives to create. I had this problem with uploading quiz results to individual students. To save space, I needed to ZIP each of 23 files and to do that with a GUI is pretty clumsy. However, I discovered that two CLI tools, zip and unzip, can make this job much easier.

unzip works just like you'd expect:

  unzip [zipfilename]
zip, on the other hand, took a little figuring out:
   zip -h                              {...dumps online help listing}
zip [zipfilename] [file to zip] {...zips and retains the original file}
zip -m [zipfilename] [file to zip] {...zips and removes the original file}
Best of all, I created a script called smush to help me out even more.
# smush - a quick and dirty script to zip pdfs

for i in *.pdf
do
echo "zipping ${i}"
zip -m $i.zip $i
done
I cd to the directory, type smush and it all works automagically. Sweet!

[Editor's note: You'll need to enter the above lines into a terminal editor such as pico, save the file, make it executable (chmod 755 filename), and then make sure it's on your path to use the script.]

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20011105000356975