tar

tar

The tar program is on all Linux systems and provides a way to create a backup of a directory quickly. The format for tar is:

 

tar options destination source

 

It is easy to get the destination and source confused so double check it. If the user mary wanted to back up her home directory to a backup partition called /bk this would be the command:

tar cvf /bk/mary_bk.tar /home/mary

 

 

Notice the options are:

c create an archive

v verbose and list all the activity

f place the archive in a file

 

Now if there were a system crash and mary needed to retrieve that tar file and expand it here is the command to do that:

 

tar xvf /bk/mary_bk.tar /

 

The options are:

x extract the files

v verbose

f read from the file

w interactive mode

z enable compression in the tar file, gzip is used

N only save files newer than the date listed

 

Notice that if mary lost her directory the whole thing could be restored by indicating where to restore it and that is why the / is important because it would recreate /home/mary from the / directory.

 

If you wanted to list the contents of the tar file to see if a specific file was located in the tar file you would use this command:

 

tar -tvf mike_bk.tar

 

drwxr-xr-x mike/mike 0 2005-09-11 07:40:31 home/mike/Desktop/

drwxr-xr-x mike/mike 0 1969-12-31 17:00:00 home/mike/Desktop/book/

-rwxr-xr-x mike/mike 54307 2003-12-30 12:40:52 home/mike/Desktop/book/00p.png

-rwxr-xr-x mike/mike 5782 2004-01-08 08:09:55 home/mike/Desktop/book/Book.stw

drwxr-xr-x mike/mike 0 1969-12-31 17:00:00 home/mike/Desktop/book/Calc/

-rwxr-xr-x mike/mike 27990 2003-08-10 23:18:57 home/mike/Desktop/book/Calc/calc.sxc

---cut---

 

Some distributions like Slackware use tarfiles to install and update programs. However, all Linux distributions can use tarfiles from the terminal. A tarball is a compressed file containing a program's directory contents which includes source code, a Makefile and documentation. This file is compressed with gzip and created as a file with tar. When both of these programs are used it creates a file extension tar.gz. Because both tar and gzip are common programs on Linux this method of distribution has become not only popular but practical. When you want to use a file that has been compressed and was created with tar you will need to perform two steps to use the program. First you will need to decompress the file, which can be done with this command:

gzip -d tarfilename.tar.gz

 

Next you will need to extract the tar file with this command:

tar xvf tarfilename.tar

Notice that since the file was decompressed the .gz extension was removed. Once this file is extracted into a directory you will need to compile it usually to make it functional. The directory that was created when the file was extracted will contain a README file that will give you complete instructions on what needs to be done to get the program to work but typically it will follow this pattern:

  1. Run the configure file that is located in the directory by placing a ./ in front of configure so that it looks like this in a terminal ./configure and then hit Enter. This will make sure that you have the proper compiler and check for dependencies.

  2. Use the “make” command to compile the source code, which creates a binary format. This command is just the word make in the terminal and then choose Enter.

  3. The next command is “make install” in a terminal which installs the binary program in the correct location.

Here is what the series of commands will look like:

./configure

make

make install

 

That process will then install the program that you are interested in using.

Here is an example of installing two programs using tar. First, chkrootkit, which is an administrative tool to check for root kits on the system and the second is firefox.

The files can be downloaded as tar.gz files.

chkrootkit.tar.gz

firefox-1.0.installer.tar.gz

 

Copy these two files to the hard drive into the appropriate folder, where you want these in the file system. Both of these files are tar files and are compressed so that to use them you must uncompress, extract and install the files. You can use one tar command to uncompress and extract:

tar -zxvf chkrootkit.tar.gz

 

Once this file is extracted then move into the directory with the cd command:

cd chkrootkit-0.43

 

Now as root run the program as root with this command:

./chkrootkit

 

The Firefox browser may be installed by a user with this command:

tar -zxvf firefox-1.0.installer.tar.gz

 

Once this file is extracted then move into the directory with the cd command:

cd firefox-installer

 

Now run the command:

./firefox-installer

 

If all the necessary dependencies are correct the program will be installed. You may find dependencies that must be fixed before a program can be installed.