How To: Extract .tgz files with Tar

How To: Extract .tgz files with Tar

.tgz files have been used in Unix for years. Originally created to handle backups to tape, it’s now commonly used to archive groups of files together such as installers for software. This is where most people run across the confusing .tgz, tar.gz, or tar.bz2 file extensions.

These instructions should be universal for most Unix systems, Linux, BSD, OS X, and even Solaris. Please feel free to leave a comment if they’re not.

To get to tar’s help files, simply type: man tar

The output will look something like this:

TAR(1) tar TAR(1)

NAME
tar – The GNU version of the tar archiving utility

SYNOPSIS
tar [options]

Operations:
[-]A –catenate –concatenate
[-]c –create
[-]d –diff –compare
[-]r –append
[-]t –list
[-]u –update
[-]x –extract –get
–delete

Common Options:
-C, –directory DIR
-f, –file F
-j, –bzip2
-p, –preserve-permissions
-v, –verbose
-z, –gzip

So for extracting tar files, we will use the x and f options. Thus:

tar xf filename.tar

Will work fine. Note that the same command should usually work for any file that has the tgz, tar.gz, or tar.bz2 extensions too. The tar command should automatically detect the file type and call gzip or b2zip. If it doesn’t there are two more commands.

For .tgz or tar.gz files, add a z to the command: tar xzf filename.tgz

For .bz2 files, add a j : tar xjf filename.tar.bz2

At this point the file should unzip and untar into the same directory as the archive file. Sometimes an auto installer will come up, but that is still pretty rare.

How To: Check OS X Disk Usage

How To: Check OS X Disk Usage

In OS X there are two ways to do everything. Via the GUI, or Via the command line. Frequently the GUI method does fine for most uses. But sometimes a bit more information is needed.

In the GUI, getting Disc Usage is simple. Open Finder, click on the drive and look at the bottom of the finder window. The number of files selected and the space available is displayed. But, this only shows the current directory and includes ALL sub folders under it.

But with a little use of the command line we can get a lot more information. Opening terminal defaults to the active user’s home directory.

At this point type du -sh * We’re adding the s for “Display an entry for each specified file,” and h for “Human-readable” output.

This will give a readout like this:
28G Desktop
41G Documents
13G Downloads
3.9G Library
0B Movies
5.1G Music
42G Pictures
121M Public
374M Sites

As can be seen this then gives a readout of each directory in the current one and provides the total space it takes up. In cases of low hard drive space this gives a good way to quickly find folders that may be too big. It could also be run in the /Users folder on multi-user machines to find out who it using all the hard drive space.