Backups and Archives using tar and gunzip
To make an archive we use the tar command which stands for tape archive. To make an archive of my home directory /home/des, cd to it and type
tar -cvf mytar.tar /home/des/
This will create the archive file mytar.tar in /home/des The -cvf stands for -c = create v = verbose and -f = file archive
To see a list of the contents of the tar file
tar -tvf /home/des/mytar.tar
To compress the tar file, cd to the directory of the tar file and type
gzip mytar.tar
This changes the tar file to a tar.gz compressed archive
To uncompress the tar.gz back to a tar
gunzip mytar.tar.gz
And to extract the archive, cd to the directory you want the files in
tar xvf /home/des/mytar.tar
You can also use a shorcut to uncompress and unpack a tar.gz in one command
gunzip -c mytar.tar.gz | tar xopf -
You can use the short version of tar and gzip which makes a .tgz compressed archive. To archive and compress a folder named des, cd to it directory and use:
tar cvfz des.tgz des
This creates a compressed archive named des.tgz. To extract the contents you can use:
tar xvzf des.tgz
This extracts the contents of des.tgz into the current directory.
If you want to extract into a specific directory then cd to that directory and use tar. For example if I wnat to untar into desdump directory.
mkdir desdump
cd desdump
tar xvfz ../des.tgz
Where ../des.tgz is the relative path to the .tgz file. You could also use the full path to the file like /home/des/des.tgz