Extracting TAR GZ Archives Via Command Line

This tutorial will show you how to zip up a folder as a tar.gz then extract the contents of a tar.gz. First start by going to the directory that contains the file that you want to compress. For demonstration purposes I will create a new folder and zip it up. Then delete the folder and unzip it to show the process working.

Step 1

To make this tutorial easier you should cd to the directory that contains the folder that you want to zip. e.g cd /tmp

To compress the folder we will use the tar command. You will then provide the name that you want to use for the archived file/folder and the name of the file/folder you want to archive.

 

tar -pczf zippedarchive.tar.gz zipme

Step 2

Use ls to check that the process was successful. You should see your newly created archive listed on the screen. You have successfully created a tar.gz archive! Now let us unzip it.

Step 3

Start by removing the old directory that we just zipped up.In this case I want to delete the directory called delete zipme. Use rmdir /zipme to delete the directory and use ls to check that is has successfully been deleted. Now you can extract the archive.
To Extract a tar.gz archive you can use the tar command again.

[root tmp]# tar xvsf zippedarchive.tar.gz

Use ls to check that the directory was successfully extracted. Below is the full process of creating a directory, archiving it, then extracting it with validation steps in between.

[root tmp]# mkdir zipme
[root tmp]# ls
zipme
[root tmp]# tar -pczf zippedarchive.tar.gz zipme
[root tmp]# ls
zipme zippedarchive.tar.gz
[root tmp]# rmdir zipme
[root tmp]# ls
zippedarchive.tar.gz
[root tmp]# tar xvsf zippedarchive.tar.gz
zipme/
[root tmp]# ls
zipme zippedarchive.tar.gz

Related Articles

Related Questions

Is upgrading from Ryzen 7 5700X to 7700X worth a 17% performance boost?

I'm considering upgrading my PC, specifically swapping out my Ryzen 7 5700X for a new Ryzen 7 7700X, as recommended by a friend. However,...

Strange Adware Notifications: Need Help!

Hey everyone! I'm dealing with a tricky situation. A client reached out saying they're getting persistent desktop notifications about having a ton of viruses....

Feeling Stuck with Coding – How Can I Improve Without AI?

I'm currently taking CS61A and I find that I can't seem to code without relying on Copilot. When I work on labs and discussions,...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Tools

Scavenger Hunt Team Randomizer

Planning a scavenger hunt and need to split participants into random teams? Whether you're organizing a school activity, a corporate team-building event, or a...

File Hash Generator Online – Get Instant MD5 and SHA-256 Hashes

Whether you are validating downloads, checking for corruption, or comparing files for duplicates, having a fast and secure way to generate file hashes is...

Visual CSS Editor for Modern Glass UI Effects

Modern UI design is all about clean, layered aesthetics, and few styles deliver this better than glassmorphism. If you're designing sleek user interfaces and...

Fast and Accurate Tap BPM Counter – Free Web Tool

Whether you're producing music, DJing live, or just figuring out the tempo of a song, knowing the BPM (beats per minute) can be critical....

Glassmorphism CSS Generator with Live Preview

Glassmorphism is one of the most visually striking design trends in modern UI. Its soft, frosted-glass effect adds depth and elegance to web interfaces,...

Add Custom Speech and Caption Boxes to Any Image Online

Creating comic-style images used to require complex design tools or specialist software. Whether you're making memes, teaching graphics, social media posts or lighthearted content,...

Latest Posts

Latest Questions