One of the simplest tasks is creating and extracting files using
gzip. Yet for most new developers this is a daunting task. These days
tar is mostly used to simply combine a few files into a single file and then
gzip is used to compress that file.
Here is a quick overview how to use
gzip to create and compress an archive:
1 2 3 4 5 6 7 8
Options give to tar are:
c to create new archive,
v to be verbose,
z to compress resulting archive with
f to write the archive to specified file. After options you can list files and dirs you want to archive.
In all examples we provide a full path to a file or dir we want to archive. In this case
tar will store files in the archive using the full path. This means once you extract the files you’ll have a complete directory structure from root dir onwards.
The way to avoid this is either to manually
cd to dir in which files are stored, or to tell
C option to change dir before archiving files.
Finally to extract an archive:
x option tells
tar to extract the archive into current directory.
For more information you can consult manual using