x
Loading
 Loading
Hello, Guest | Login | Register

Ands and Ifs

In the past few months, this column has explored the intricacies of Linux’s bash shell. Since we’re on a roll, we’re going to continue this month by looking at the shell’s logical operators and conditional statements — the ands and ifs. Along the way, we’ll use conditional statements to construct a simple archive command that can help you use every available byte of disk storage space.

In the past few months, this column has explored the intricacies of Linux’s bash shell. Since we’re on a roll, we’re going to continue this month by looking at the shell’s logical operators and conditional statements — the ands and ifs. Along the way, we’ll use conditional statements to construct a simple archive command that can help you use every available byte of disk storage space.

Getting the Size of a File

If you’re a PC veteran, you may recall the days of the 5 MB hard drive. By today’s standards, these drives were pricey, pokey, and puny. Today, even 80 GB drives are common. However, even your 80 GB drives are probably packed to the gills.

One way to better use your available disk space is to compress many of your large text files. The gzip utility is ideally suited to this task. The problem is merely one of identifying the proper files to compress.

Since there’s little to be gained by compressing a small file, candidates for compression should be large files. And, since uncompressing a file involves a small inconvenience, it’s best to compress only files that aren’t in regular use. We could use the find command, which was explained in the April 2001 column (check it out online at http://www.linux-mag.com/2001-04/newbies_01.html). However, let’s see if we can do the job the hard way, learning something and gaining some flexibility along the way.

First, let’s create a command that displays the size…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace