To help everything sink in, follow this quick exercise:
- 1 -
Enter the following to create a temporary directory for this exercise:
mkdir work
- 2 -
Create the files 1, 2, and 3 in the work directory with the following command:
touch work/1 work/2 work/3
- 3 -
Now let's archive the work directory and compress it at the same time using gzip (indicated by the z flag). If the z flag had not been used then it would've been proper to call the archive work.tar, but because of the z flag it's proper to call the file work.tar.gz. Enough explaining, enter the following:
tar cvfz work.tar.gz work
- 4 -
Now that the directory has been archived, the work directory can be removed:
rm -r work
- 5 -
Now let's extract the archive. Once again you will be required to uncompress the archive at the same time, (this time using gzip's partner in crime: gunzip) again indicated by the z flag. (If this had been a .tar file then you wouldn't use the z flag.) Anyway here's the command:
tar xvfz work.tar.gz
- 6 -
Now that you have no more need of work.tar.gz, you can remove it:
rm work.tar.gz
- 7 -
To prove that everything's worked out fine, enter:
tree work
...to display the following:
work
|-- 1
|-- 2
`-- 3
- 8 -
And now that the exercise is finished, enter:
rm -r work
|