Create and Extract tar.gz on Ubuntu

Reading time ~1 minute

Create tar.gz archives

tar czf new-tar-file-name.tar.gz file-or-folder-to-archive

c - create new archive z - compress the archive using gzip f - use archive file

Extract archives

tar -xzf tar-file-name.tar.gz

x - extract the archive. z - uncompress the archive using gzip. f - use archive file.

Let’s do it.

I only want to compress 3 files. When I extract archive what I want to see is files in the directory.

$ tree file_dir/
file_dir/
├── file1.txt
├── file2.txt
└── file3.txt

$ cd file_dir
$ tar czf files.tar.gz .
tar: .: file changed as we read it

# moved files.tar.gz to different directory
$ tar -xzf files.tar.gz 
$ ls
file1.txt  file2.txt  file3.txt  file_dir  files.tar.gz

Cheers!

Imogene Run

# Breathing Through the Sky: My Imogene Pass Run![Start line](../images/2025-09-07/start.jpeg)This weekend I had the privilege of lining ...… Continue reading

Running Post Hysterectomy

Published on April 01, 2023

Refinance

Published on February 19, 2021