Linux TAR Command

Quick Start: Here we’l present quick start examples explained.

Create linux tar gz (Gzip) archive

tar -czvf myarchive.tgz mydirectory/

We use the -t option to create an linux tar archive
-c, –create create a new archive

Note that .tgz is the same thing as .tar.gz

Create linux simple tar archive (withouth compresion)

tar -cvf myarchive.tar mydirectory/

Extracting linux tar archive:

Extract linux tar gz (Gzip) archive
tar -xzvf mystuff.tgz

Extract linux simple tar archive
tar -xvf mystuff.tar

We use -x to extract the files form the tar archive
-x, –extract, –get extract files from an archive

Extract linux tar archive to speciefied directory
tar -xvzf filename.tar.gz -C /desired/path

And now let us shortly explain this command

Usage: tar [OPTION]… [FILE]…

Let us check the option used in this example

-c, –create                      create a new archive
-z, –gzip, –ungzip        filter the archive through gzip
-v, –verbose                   verbosely list files processed
-f, –file=ARCHIVE          use archive file or device ARCHIVE

-C directory file
Performs a chdir  operation on directory and performs the c (create) or r (replace) operation on file .
In c and r mode, this changes the directory before adding the following files. In x mode, change directories after opening the archive but before extracting entries from the archive.

Testing / viewing your archive

tar -tvf myarchive.tar
tar -tzvf myarchive.tgz

Here we used the – t opton
-t, –list                           list the contents of an archive


Go ahead, try out these commands and stay tuned; we will come up with more doccumentation on linux tar command

About these ads

Tags: , , ,

15 Responses to “Linux TAR Command”

  1. Matt Says:

    Thanks for the great help keep the good work

  2. Webdevelopment Says:

    Thanks, as newbe it surprises me that you cant extract to a defined location.
    Copy the tarball to the root of the location first.

  3. Matt Says Says:

    Thanks for the great help keep the good work

  4. Comprimir y descomprimir archivos con tar en linux « microjuanan Says:

    [...] [...]

  5. Mihai Says:

    You can extract to a defined location using:

    tar xvf yourstuff.tar -C your/path/here

  6. Linux Tip: Recursive FTP Backup | colin odell dot com Says:

    [...] above! You can extend this further by using cronjobs to run this command on a set schedule, compressing the files into a single archive file, and [...]

  7. tudor Says:

    how can i extract to a specified path?

    • Says:

      You can extract to a specified path using:

      tar xzvf yourarchive.tar.gz -C your/path/here

      For this we will use -C ( not -c , wicht meand create )

      -C directory file

      Performs a chdir (see “cd” command ) operation on directory and performs the c (create) or r (replace) operation on file . Use short relative path names for file .
      If file is `.’, archive all files in directory. This option enables archiving files from multiple directories not related by a close common parent.

  8. Chris Says:

    regarding the “xzvf” do these commands have to specified in a specific order or do it not really matter as long as they are present?

  9. Linux Archive verwenden und komprimieren Says:

    [...] [...]

  10. Ernest Says:

    Thank you for posting this which helped a lot ….

  11. ~I Says:

    if i have done
    > tar -xvfz hugetarfile.tar.gz
    and aborted it with ctrl+c
    and found that hugetarfile.tar.gz has become tinytarfile.tar.gz
    Is there any magic spells to make tinytarfile back to huge <.< , or the data loss is irreversible

  12. perintah tar pada linux | Nikmat tuhan yang mana yang dapat kamu ingkari Says:

    […] […]

  13. Calin Tofan Says:

    When extracting an archive, the source should not change, I will try to replicate the situation …

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: