File Storage and Compression on UNIX

On Linux you do not have a GUI which in turn makes hard drive storage a little bit complicated. However file storage and compression are important skills to master. Memory is crucial on a computer.

We are going to list some commands to get you up and running:

df –h

Either a system administrator or an unpriviledged user can see how much disk space is available on their Unix or Linux system by using the df (Disk Free) command.

du -h

You can also check how much space is being used in your home directory.

Compression

Another important tool that we have access is compression. Compressing files is very important and we have access to two formats: TAR and ZIP

To compress a file type the following command:

tar -cf out-file.tar (filename)
gzip out-(filename).tar

To decompress we do the following:

tar -zxvf out-file.tar.gz

Tape Archive File Compression (Tarballs)

The tar utility stands for "tape archive" and was commonly used on older Unix systems to backup files on tape. Although new storage devices are available today, this utility is still used.

tar -cf (new_compression name).tar (file names to be compressed)

ZIPPED TARBALLS

To compress those "archived" files in order to save space, you can use the "zip" utility. Let's zip the tarball called "out.tz" to create a "zipped-tarball" that we will call "out.tz.gz".

Issue the following command:

gzip(filename).tar

The file gets renamed to

(filename).tar.gz

RESTORING A "ZIPPED" TARBALL

Usually, you obtain "zipped tarballs" from CDs, copy them from other directory paths on your system, or download them from the Internet.

You generally follow the same procedure as before, but in the reverse order and using Unix commands.

  • Unzip to create "tarball".
  • Decompress "tarball" to obtain original files.

To Unzip, you use the "gunzip" utility. To obtain the "tarball", issue the following command:

gunzip (filename).tar.gz

This recovers (unzips) the original "tarball" called out.tz

Now, to obtain the orginal files (out.1, out.2, out.3), issue the following command:

tar -xvf (filename).tar