Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Tar unlike zip allow you to keep permissions. As such it is the defacto utility for making backups. Also if you can keep your user UIDs consistent across environments, tar allows for quick disaster recovery.

Warning

This article still needs to be completed.

Must Read

Before using tar there are one critical behaviour to understand, always tar using relative paths. Otherwise you risk overwriting your data when untaring.

Warning

TBC Roderick, put Put an example of that here with more details.

Create linux tar gz (Gzip) archive

tar -czvf myarchive.tgz tar.gz ./mydirectory/We use the -t option to create an linux tar archive

Note

The f flag must come at the end or you will get an error.

Here is what each flag does,

Panel

-c, –create create a new archive


...

Note that .tgztar.gz is the same thing as .tartgz.gz

Create linux simple tar archive (withouth compresion)

tar -cvf myarchive.tar mydirectory/


Extracting

...

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

...

and note the The f flag must come at the end or you will get an error.

 

Extract linux simple tar archive
tar -xvf mystuff.tar

Code Block
languagebash
tar -xzvf mystuff.tgz

In some scenarios, you are moving between systems and want to extract maintaining permissions of users external to yourself. In this scenario you must ensure you UIDs are the same across systems,

Code Block
languagebash
sudo tar -xzvf mystuff.tgz

....

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

...

Code Block
languagebash
# To tar the directory
sudo tar -zcvpf tarfile.tar.gz ./folder/
 
# To untar and gunzip the file in one command
sudo tar -zxvpf tarfile.tar.gz
 
# Encrypting a tar
...

...