Using tar

mihalis's picture

This blog post will try to show you how to use the tar utility.

Look at the contents of the code directory:

$ ls -l code/
total 24
-rw-r--r--@ 1 mtsouk staff 50 Nov 16 18:12 generatePassword.go
-rw-r--r--@ 1 mtsouk staff 50 Nov 16 18:12 randomNumbers.go
-rw-r--r--@ 1 mtsouk staff 50 Nov 16 18:12 stack.go

You can create a new tar file as follows:

$ tar zcvf code.tar.gz code
a code
a code/generatePassword.go
a code/randomNumbers.go
a code/stack.go
$ ls -l code.tar.gz
-rw-r--r-- 1 mtsouk staff 494 Nov 24 22:38 code.tar.gz

The preceding file is also compressed using the gzip utility because of the z option.
You can list the contents of an existing tar file (t) as follows:

$ tar ztvf code.tar.gz
drwxr-xr-x 0 mtsouk staff 0 Nov 10 20:32 code/
-rw-r--r-- 0 mtsouk staff 50 Nov 16 18:12 code/generatePassword.go
-rw-r--r-- 0 mtsouk staff 50 Nov 16 18:12 code/randomNumbers.go
-rw-r--r-- 0 mtsouk staff 50 Nov 16 18:12 code/stack.go

You can extract (x) an existing tar file as follows:

$ tar zxvf code.tar.gz
x code/
x code/generatePassword.go
x code/randomNumbers.go
x code/stack.go

Tags: