Archiving and Compression
Before gunzipping a file (or files) with gunzip, you might want to verify that they're going to gunzip correctly without any file corruption. To do this, use the -t (or --test) option.
$ gzip -t paradise_lost.txt.gz $
That's right: If nothing is wrong with the archive, gzip reports nothing back to you. If there's a problem, you'll know, but if there's not a problem, gzip is silent. That can be a bit disconcerting, but that's how Unix-based systems work. They're generally only noisy if there's an issue you should know about, not if everything is working as it should.
Working with bzip2 is pretty easy if you're comfortable with gzip, as the creators of bzip2 deliberately made the options and behavior of the new command as similar to its progenitor as possible.
$ ls -l -rw-r--r-- scott scott 1236574 moby-dick.txt $ bzip2 moby-dick.txt $ ls -l -rw-r--r-- scott scott 367248 moby-dick.txt.bz2
Just like gzip, bzip2 leaves you with just the .bz2 file. The original moby-dick.txt is gone. To keep the original file, use the -c (or --stdout) option and pipe the output to a filename that ends with .bz2.
$ ls -l -rw-r--r-- scott scott 1236574 moby-dick.txt $ bzip2 -c moby-dick.txt > moby-dick.txt.bz2 $ ls -l -rw-r--r-- scott scott 1236574 moby-dick.txt -rw-r--r-- scott scott 367248 moby-dick.txt.bz2
If you look back at "Archive and Compress Files Using gzip," you'll see that gzip and bzip2 are incredibly similar, which is by design.
Just as with zip and gzip, it's possible to adjust the level of compression that bzip2 uses when it does its job. The bzip2 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.
$ ls -l -rw-r--r-- scott scott 1236574 moby-dick.txt $ bzip2 -c -1 moby-dick.txt > moby-dick.txt.bz2 $ ls -l -rw-r--r-- scott scott 1236574 moby-dick.txt -rw-r--r-- scott scott 424084 moby-dick.txt.bz2 $ bzip2 -c -9 moby-dick.txt > moby-dick.txt.bz2 $ ls -l -rw-r--r-- scott scott 1236574 moby-dick.txt -rw-r--r-- scott scott 367248 moby-dick.txt.bz2
From 424KB with 1 to 367KB with 9 — that's quite a difference! Also notice the difference in ultimate file size between gzip and bzip2. At -9, gzip compressed moby-dick.txt down to 488KB, while bzip2 mashed it even further to 367KB. The bzip2 command is noticeably slower than the gzip command, but on a fast machine that means that bzip2 takes two or three seconds longer than gzip, which frankly isn't much to worry about.
Note - If you want to be clever, define an alias in your .bashrc file that looks like this:
alias bzip2='bzip2 -9'
That way, you'll always use -9 and won't have to think about it.
In the same way that bzip2 was purposely designed to emulate gzip as closely as possible, the way bunzip2 works is very close to that of gunzip.
$ ls -l -rw-r--r-- scott scott 367248 moby-dick.txt.bz2 $ bunzip2 moby-dick.txt.bz2 $ ls -l -rw-r--r-- scott scott 1236574 moby-dick.txt
You'll notice that bunzip2 is similar to gunzip in another way: Both commands remove the original compressed file, leaving you with the final uncompressed result. If you want to ensure that you have both the compressed and uncompressed files, you need to use the -c option (or --stdout or --to-stdout) and pipe the results to the file you want to create.
$ ls -l -rw-r--r-- scott scott 367248 moby-dick.txt.bz2 $ bunzip2 -c moby-dick.txt.bz2 > moby-dick.txt $ ls -l -rw-r--r-- scott scott 1236574 moby-dick.txt -rw-r--r-- scott scott 367248 moby-dick.txt.bz2
It's a good thing when commands copy each other's options and behavior, as it makes them easier to learn. In this, the creators of bzip2 and bunzip2 showed remarkable foresight.
Note - If you're not feeling favorable toward bunzip2, you can also use bzip2 -d (or --decompress or --uncompress).
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- SUSE LLC's SUSE Manager
- My +1 Sword of Productivity
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- Managing Linux Using Puppet
- Non-Linux FOSS: Caffeine!
- SuperTuxKart 0.9.2 Released
- Doing for User Space What We Did for Kernel Space
- Parsing an RSS News Feed with a Bash Script
- Google's SwiftShader Released
- Rogue Wave Software's Zend Server
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide