Working with tar. The basics.

STEP 1 (Using the tar command on the directory /stuff)

Suppose you have a directory /stuff
To tar everything in stuff to create a “.tar” file.

$ tar -cvf stuff.tar stuff

Which will create “stuff.tar”.

STEP 2 (Using the tar command to create a “.tar.gz” of /stuff)

$ tar -czf stuff.tar.gz stuff

STEP 3 (List the files in the archive)

$ tar -tzf stuff.tar.gz
$ tar -tf stuff.tar

STEP 4 (A way to list specific files)

Note, pipe the results to a file and edit

$ tar -tzf stuff.tar.gz > mout

Then, edit mout to only include the files you want

$ tar -T mout -xzf stuff.tar.gz

The above command will only get the files in mout.
Of couse, if you want them all

$ tar -xzf stuff.tar.gz


$ tar -zcvf – stuff|openssl des3 -salt -k secretpassword | dd of=stuff.des3

This will create stuff.des3…don’t forget the password you
put in place of secretpassword. This can be done interactively as

$ dd if=stuff.des3 |openssl des3 -d -k secretpassword|tar zxf –

NOTE: above there is a “-” at the end… this will
extract everything.


More examples:


  • An archive named archive.tar with the files file_1.txt and all files of the type * .pdf Create:
    tar -cf archive.tar file_1.txt *.pdf
  • An archive with the folder data , including all subfolders and files too create with:
    tar -cf archive.tar data/
  • Creating an archive, add two files and subsequently with gzip compress:
    tar -czf archive.tar.gz datei_1.txt datei_2.txt


  • Display the contents of a (encoded) archive detail:
    tar -tvf archive.tar


  • Only adds files to, if they are more recent than its counterpart in the archive:
    tar -uf archive.tar data

    Unfortunately, when you update any subdirectories to be considered!


  • An archive file to add:
    tar -rf archive.tar file_1.txt


  • Verify the contents of an archive with the file system:
    tar -dvf archive.tar

    The command should be run in the directory where the files are in the archive is stored.


  • All files from an archive in the current folder extract:
    tar -xf archiv.tar
  • All files from one with gzip compressed archive in the original folder extract:
    tar -xzf archive.tar.gz -C /
  • All files in a specific directory extract (the destination directory must already exist):
    tar -xzf archive.tar.gz -C /PATH/TO/FOLDER
  • A specific file from an archive extract:
    tar -xzf archive.tar.gz Path/Filename

    It must Path/Filename just exist in the archive file. A specified subdirectory Path is created in the current directory automatically (with relative path).

Working with archive files (.tar, .tgz, .tar.gz, .tar.bz2)

tar zxvf file.tar.gz
Uncompress and extract the gzipped tar file file.tar.gz

tar jxvf file.tar.gz
Uncompress and extract the bzipped tar file file.tar.gz

tar zcvf file.tar.gz dirname
Archive and gzip compress the directory dirname into the file file.tar.gz

tar jcvf file.tar.gz dirname
Archive and bzip2 compress the directory dirname into the file file.tar.gz

You found a lot of stuff about tar and what you can do with it take a look at the following Pages:


Tar at the Web

For us Turkish user