Greg Hinkel's UNIX Tip of the Week for April 7, 1996
Reducing your disk usage.
Seems like disk space is always full. No matter how much you have it's never
enough.
While the preferred method is to delete unneeded files/directories or save
them off to tape, an alternative is to compress them so that they use as
little space as possible (without deleting them).
UNIX provides "compress" and "uncompress" commands (who ever said UNIX commands
were terse and hard to understand). These commands work for both ASCII text
files as well as binary files. So, let's say you have a file named "bigfile"
that you don't use very often but you don't wanna delete it.
> ls -l bigfile*
-rw------- 1 bugsbunny 922112 Apr 9 16:57 bigfile
> compress bigfile
> ls -l bigf*
-rw------- 1 bugsbunny 504625 Apr 9 16:57 bigfile.Z
Notice that "bigfile" no longer exists, and in it's place is a file by the
same name but with a .Z appended to it. UNIX "standard" notation is that any
file with a .Z on the end is a compressed file. In this case we almost got a
50% reduction in file size. The compression ratio will vary based on the
contents of the file.
To get bigfile back you can use uncompress.
> uncompress bigfile
> ls -l bigfile*
-rw------- 1 bugsbunny 922112 Apr 9 16:57 bigfile
Note, you don't have to specify the ".Z" to uncompress, but you can if you
wanna.
By the way, you have to have enough disk space to hold both the compressed and
uncompressed files whenever you use the "compress" or "uncompress" commands.
That's cause it creates the "new" file and doesn't delete the "old" file till
the command completes successfully.
If you wanna see what's in bigfile.Z without creating the file "bigfile" you
can use zcat. This command will uncompress a file and write the output to
standard output, leaving the original file intact (bigfile.Z in this case).
So, "zcat bigfile.Z | more" is useful for reading text files. Or, "zcat
bigfile.Z | grep something" is good for searching for something in a
compressed file. Also, "zcat bigdir.tar.Z | tar tvf -" is useful for looking
at the contents of a compressed tar file.
There are other compression utilities available from the net, such as
gzip/gunzip. These utilities generally provide a better compression ratio
than compress/uncompress, however they take longer to execute (at least that
is what I have experienced). "Standard" notation is that files ending with
".gz" are files compressed with gzip. Also, gunzip will uncompress .Z files
as well as .gz files.
So, do everybody a favor and compress those files that you don't use regularly.
Previous Tip of the Week ·
Next Tip of the Week ·
Index
Greg's Home Page
Greg Hinkel / (hinkelgc AT ornl.gov)
Last Modified: Friday, 02-Sep-2005 12:52:31 EDT
Visitors: 5024 since March 18, 1996