Create and extract a .tar.gz archive

Create

tar -zcvf tar-archive-name.tar.gz source-folder-name

-z : Compress archive using gzip program
-c: Create archive
-v: Verbose i.e display progress while creating archive
-f: Archive File name

Extract

tar -zxvf tar-archive-name.tar.gz

Extract .tgz

tar xfz tar-archive-name.tgz

-x: Extract files

Extract and strip 1 level

Not strip

tar xfz my-file.tgz -C /tmp/

ls /tmp/my-file
- my-file
ls /tmp/my-file/my-file
- my-sub-file-01

Strip

tar xfz /opt/tmp/my-file.tgz --strip-components=1 -C /tmp/

ls /tmp/my-file
- my-sub-file-01

Loading