Archiving and Compression
It's possible to adjust the level of compression that zip uses when it does its job. The zip command uses a scale from 0 to 9, in which 0 means "no compression at all" (which is like tar, as you'll see later), 1 means "do the job quickly, but don't bother compressing very much," and 9 means "compress the heck out of the files, and I don't mind waiting a bit longer to get the job done." The default is 6, but modern computers are fast enough that it's probably just fine to use 9 all the time.
Say you're interested in researching Herman Melville's Moby-Dick, so you want to collect key texts to help you understand the book: Moby-Dick itself, Milton's Paradise Lost, and the Bible's book of Job. Let's compare the results of different compression rates.
$ ls -l -rw-r--r-- scott scott 102519 job.txt -rw-r--r-- scott scott 1236574 moby-dick.txt -rw-r--r-- scott scott 508925 paradise_lost.txt $ zip -0 moby.zip *.txt adding: job.txt (stored 0%) adding: moby-dick.txt (stored 0%) adding: paradise_lost.txt (stored 0%) $ ls -l -rw-r--r-- scott scott 102519 job.txt -rw-r--r-- scott scott 1236574 moby-dick.txt -rw-r--r-- scott scott 1848444 moby.zip -rw-r--r-- scott scott 508925 paradise_lost.txt $ zip -1 moby.zip *txt updating: job.txt (deflated 58%) updating: moby-dick.txt (deflated 54%) updating: paradise_lost.txt (deflated 50%) $ ls -l -rw-r--r-- scott scott 102519 job.txt -rw-r--r-- scott scott 1236574 moby-dick.txt -rw-r--r-- scott scott 869946 moby.zip -rw-r--r-- scott scott 508925 paradise_lost.txt $ zip -9 moby.zip *txt updating: job.txt (deflated 65%) updating: moby-dick.txt (deflated 61%) updating: paradise_lost.txt (deflated 56%) $ ls -l -rw-r--r-- scott scott 102519 job.txt -rw-r--r-- scott scott 1236574 moby-dick.txt -rw-r--r-- scott scott 747730 moby.zip -rw-r--r-- scott scott 508925 paradise_lost.txt
In tabular format, the results look like this:
|Book||zip -0||zip -1||zip -9|
|Total (in bytes)||1848444||869946||747730|
The results you see here would vary depending on the file types (text files typically compress well) and the sizes of the original files, but this gives you a good idea of what you can expect. Unless you have a really slow machine or you're just naturally impatient, you should just use -9 all the time to get the maximum compression.
Note - If you want to be clever, define an alias in your .bashrc file that looks like this:
alias zip='zip -9'
That way you'll always use -9 and won't have to think about it.
The Zip program allows you to password-protect your Zip archives using the -P option. You shouldn't use this option. It's completely insecure, as you can see in the following example (the actual password is 12345678):
$ zip -P 12345678 moby.zip *.txt
Because you had to specify the password on the command line, anyone viewing your shell's history (and you might be surprised how easy it is for other users to do so) can see your password in all its glory. Don't use the -P option!
Instead, just use the -e option, which encrypts the contents of your Zip file and also uses a password. The difference, however, is that you're prompted to type the password in, so it won't be saved in the history of your shell events.
$ zip -e moby.zip *.txt Enter password: Verify password: adding: job.txt (deflated 65%) adding: moby-dick.txt (deflated 61%) adding: paradise_lost.txt (deflated 56%)
The only part of this that's saved in the shell is zip -e moby.zip *.txt. The actual password you type disappears into the ether, unavailable to anyone viewing your shell history.
Caution - The security offered by the Zip program's password protection isn't that great. In fact, it's pretty easy to find a multitude of tools floating around the Internet that can quickly crack a password-protected Zip archive. Think of password-protecting a Zip file as the difference between writing a message on a postcard and sealing it in an envelope: It's good enough for ordinary folks, but it won't stop a determined attacker.
Also, the version of zip included with some Linux distros may not support encryption, in which case you'll see a zip error: "encryption not supported." The only solution: recompile zip from source. Ugh.
|Using Salt Stack and Vagrant for Drupal Development||May 20, 2013|
|Making Linux and Android Get Along (It's Not as Hard as It Sounds)||May 16, 2013|
|Drupal Is a Framework: Why Everyone Needs to Understand This||May 15, 2013|
|Home, My Backup Data Center||May 13, 2013|
|Non-Linux FOSS: Seashore||May 10, 2013|
|Trying to Tame the Tablet||May 08, 2013|
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- New Products
- Tech Tip: Really Simple HTTP Server with Python
- RSS Feeds
- Find new cell phone and tablet pc
41 min 3 sec ago
2 hours 9 min ago
- Automatically updating Guest Additions
3 hours 18 min ago
- I like your topic on android
4 hours 4 min ago
- Reply to comment | Linux Journal
4 hours 26 min ago
- This is the easiest tutorial
10 hours 40 min ago
- Ahh, the Koolaid.
16 hours 19 min ago
- git-annex assistant
22 hours 18 min ago
- direct cable connection
22 hours 41 min ago
- Agreed on AirDroid. With my
22 hours 51 min ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!