User Tools

Site Tools


guides:tar

This is an old revision of the document!


Working with the Tape Archive Utility (TAR)

To make a tar file from the directory homework1

$ tar czf homework1.tgz homework1

To check the contents of a tar file called homework1.tgz

$ tar tzf homework.tgz

To extract the contents of a tar file called homework1.tgz

$ tar xzf homework1.tgz

Overview

tar or the Tape ARchive utility is a program that is used for combining multiple files into a single file. This is the format that is used to transfer multiple files in the majority of open source project.

Tar files are frequently used to transfer the contents of a directory. The examples on this page assume that you want to transfer all of the files in a directory called homework1 . Further assume the contents of this directory are two files, hello.cpp and Makefile .

$ ls
Makefile  hello.cpp

Files created with tar frequently have the extension .tar. The file homework1.tar is the conventional name used for a tar file containing the directory homework1.

Tar is frequently used in conjunction with compression utilities. GNU zip (gzip) is a common choice for this. A tar file which has been compressed with gzip will frequently have the extension .tgz or even .tar.gz. In this case homework1.tgz or homework1.tar.gz are the conventional names for a tar file containing the directory homework1 which has been compressed with gzip.

This page is a summary, there are other ways that tar can be employed.

Creating a TAR File

The best practice is to work on each project in a folder or directory. For this example the code for a project is located in the directory homework1.

  1. Move one directory above the homework1 directory
    1. If you can see the directory you wish to create a tar archive of when you type ls you are in the correct directory.
    2. $ ls 
      homework1
  2. type the command tar cvzf homework1.tgz homework1
    1. c tells tar to create a tar archive.
    2. v tells tar to show you what it is adding to the archive
    3. z tells tar to use gnuzip to compress the resulting file
    4. f tells tar to write the output to a file, not to the tape deck
    5. homework1 is the name of the directory you wish to place in the tar file
    6. homework1.tgz is the name of the output file.

In the following example

$ ls
homework1
 
$ tar cvzf homework1.tgz homework1
homework1/
homework1/Makefile
homework1/hello.cpp
 
$ ls
homework1  homework1.tgz

Checking the Contents of a TAR File

Extracting files from a TAR File

Tar Files and WinSCP

guides/tar.1597504407.txt.gz · Last modified: 2022/08/02 11:59 (external edit)