3.0 University logo
  • Home
  • About us
  • All Courses
    • Cybersecurity Programs
      • Certified Ethical Hacker (CEH v13)
      • Certified SOC Analyst
      • Certified Penitration Testing Professional
      • Computer Hacking Forensic Investigator
      • Certified Cybersecurity Technician (CCT)
      • Certified AI Program Manager
      • Certified Offensive AI Security Professional
      • Certified Responsible AI Governance & Ethics Professional
      • Artificial Intelligence Essentials
    • Crypto Market Programs
    • Blockchain & Web3 Programs
      • Digital Assets Trading & Analysis Program
      • Certified Web3 Strategy & Growth Specialist
      • Certified Web3 Governance & Compliance Expert
      • Full Stack Blockchain Developer Program
      • Private Blockchain Developer Program
      • Public Blockchain Developer Program
    • Designs Programs
      • Jewellery Design Executive Program
      • Gems & Diamond Specialist Program
      • Jewellery Business Specialist Program
  • Schools
    • School of Decentralized Economics
    • School of Cyber Resilience
    • School of Intelligent Systems
    • School of Design Thinking
  • Partners
    • Certification & Knowledge Partner
    • Academic Partner
    • Hiring Partner
    • Delivery Partner
    • Affiliate Partner
    • Hybrid Center Partner
  • Blog
  • 3.0 TV
  • Home
  • About us
  • All Courses
    • Cybersecurity Programs
      • Certified Ethical Hacker (CEH v13)
      • Certified SOC Analyst
      • Certified Penitration Testing Professional
      • Computer Hacking Forensic Investigator
      • Certified Cybersecurity Technician (CCT)
      • Certified AI Program Manager
      • Certified Offensive AI Security Professional
      • Certified Responsible AI Governance & Ethics Professional
      • Artificial Intelligence Essentials
    • Crypto Market Programs
    • Blockchain & Web3 Programs
      • Digital Assets Trading & Analysis Program
      • Certified Web3 Strategy & Growth Specialist
      • Certified Web3 Governance & Compliance Expert
      • Full Stack Blockchain Developer Program
      • Private Blockchain Developer Program
      • Public Blockchain Developer Program
    • Designs Programs
      • Jewellery Design Executive Program
      • Gems & Diamond Specialist Program
      • Jewellery Business Specialist Program
  • Schools
    • School of Decentralized Economics
    • School of Cyber Resilience
    • School of Intelligent Systems
    • School of Design Thinking
  • Partners
    • Certification & Knowledge Partner
    • Academic Partner
    • Hiring Partner
    • Delivery Partner
    • Affiliate Partner
    • Hybrid Center Partner
  • Blog
  • 3.0 TV
    Login
    ₹0.00 0 Cart

    Learn Articles

    • Home
    • Learn Articles

    How to Zip, Unzip, Tar and Extract tar.gz Files in Linux

    • Posted by 3.0 University
    • Date July 13, 2026
    • Comments 0 comment

    To unzip a file in Linux, run unzip filename.zip in your terminal. To extract a tar.gz file, use tar -xzvf filename.tar.gz. These two commands handle the vast majority of compressed files you will encounter on any Linux server or desktop.

    • zip and unzip handle .zip files; they are cross-platform and great for sharing with Windows users.
    • tar -czvf creates a compressed .tar.gz archive; tar -xzvf extracts it.
    • The flags c, z, v, f each mean something specific, and once you know that, you will never need to look them up again.
    • gzip compresses single files; tar bundles multiple files first, then gzip compresses the bundle.
    • A .tgz file is identical to a .tar.gz file, just a shorter extension.

    How to Zip and Unzip Files in Linux

    Most Linux distributions do not ship with the zip utility installed by default. On Ubuntu or Debian, run sudo apt install zip unzip. On Fedora or RHEL-based systems, it is sudo dnf install zip unzip. Takes about ten seconds. In Indian IT environments, Ubuntu is the most common desktop Linux distribution used in startups and CDAC training labs, so the apt command is the one you will use most often.

    Creating a zip archive

    To create a zip file from a single file: zip output.zip file.txt. To zip an entire folder, you need the -r flag, which tells zip to recurse into subdirectories.

    zip -r project.zip project/

    That single command is how to zip a folder in Linux. The -r flag is the one people forget, and without it, zip silently skips every subdirectory inside the folder.

    Extracting a zip file in Linux

    To unzip a file in Linux, the basic command is: unzip archive.zip. That dumps everything into the current directory. If you want a clean extraction into its own folder, use: unzip archive.zip -d /path/to/destination/.

    The -l flag lets you peek inside without extracting: unzip -l archive.zip. Useful when you are on a server and do not want to accidentally unpack 2,000 files into your home directory.

    Useful zip flags at a glance

    Flag What it does Example
    -r Recurse into directories zip -r out.zip folder/
    -9 Maximum compression (slower) zip -9 -r out.zip folder/
    -e Encrypt with password zip -e secure.zip file.txt
    -d (unzip) Extract to specific directory unzip file.zip -d /tmp/
    -l (unzip) List contents without extracting unzip -l file.zip

    How to Tar a Directory and Extract tar.gz Files in Linux

    The tar command confuses beginners because the flags look like random letters. They are not. Once you decode them, you will type these commands from memory. According to the Stack Overflow Developer Survey 2023, over 65% of professional developers work with Linux environments regularly, and tar is among the most frequently used archiving tools in those environments.

    Decoding the tar flags: c, z, v, f

    Think of it as a four-letter mnemonic:

    • c = Create a new archive
    • x = eXtract an existing archive
    • z = use gZip compression (produces .tar.gz or .tgz)
    • v = Verbose output (shows files as they are processed)
    • f = the next argument is the File name

    So tar -czvf means: Create, with gzip, verbose, filename follows. And tar -xzvf means: eXtract, with gzip, verbose, filename follows. That is the whole puzzle solved.

    Creating a tar.gz archive

    To tar a directory in Linux: tar -czvf archive.tar.gz /path/to/directory/

    Real example: you are backing up a Django project on your server at /var/www/myapp/. You would run: tar -czvf myapp_backup.tar.gz /var/www/myapp/. The terminal prints each filename as it is added, and you get a single compressed archive when it is done. This workflow is standard in Indian startup deployments on AWS and Azure where engineers back up application directories before deployments.

    Extracting a tar.gz file in Linux

    To extract a tar.gz file: tar -xzvf archive.tar.gz

    To extract into a specific folder: tar -xzvf archive.tar.gz -C /destination/path/

    The -C flag is the one most tutorials skip, and it is genuinely useful. Without it, tar extracts everything into whatever directory you are currently in.

    How to open a .gz file in Linux (single file, not a tar)

    A plain .gz file is a single file compressed with gzip, not a bundle. You open it with: gunzip filename.gz. That replaces the .gz file with the decompressed original. If you want to keep the compressed version, use: gzip -dk filename.gz.

    According to GNU’s official gzip documentation, gzip typically achieves 60-70% compression on text files and around 20-30% on already-compressed formats like JPEG or MP4. Do not waste time gzipping images or video files.

    How to open a .tgz file in Linux

    A .tgz file is exactly the same as a .tar.gz file. Same format, same command: tar -xzvf filename.tgz. Some older software distributions, including many tools found on Indian government open-data portals and academic FTP servers run by institutions like IIT and NIT, use .tgz purely to save characters in filenames. Do not let it confuse you.

    Other compression formats: bzip2 and xz

    You will occasionally encounter .tar.bz2 and .tar.xz files, especially when downloading Linux kernel source packages or software from academic repositories. To extract a .tar.bz2 file, replace the z flag with j: tar -xjvf archive.tar.bz2. For .tar.xz, use J: tar -xJvf archive.tar.xz. According to a 2022 Linux Foundation report on open source tooling, xz compression is increasingly used for distributing large software packages due to its superior compression ratio compared to gzip, often achieving 15-20% better reduction on source code.

    Installing software from a tar.gz file

    Many Linux tools, especially those you download from GitHub or developer sites, come as .tar.gz source packages. The typical workflow is: extract the archive, read the README or INSTALL file, then run ./configure, make, and sudo make install. This is called compiling from source, and it is a skill worth knowing if you are heading into DevOps or system administration work. The DevOps interview questions guide at 3.0 University covers exactly the kind of environment where you will do this regularly.

    zip vs tar.gz: Which One Should You Use?

    Both formats compress files, but they serve different purposes. Choosing the wrong one is not catastrophic, but it does create unnecessary friction.

    Criteria zip tar.gz
    Cross-platform support Excellent (Windows, Mac, Linux) Linux/Mac native; needs 7-Zip on Windows
    Compression ratio (text files) ~60% reduction ~65-70% reduction
    Preserves Unix permissions Partial Yes, fully
    Best for Sharing files across OS types Linux server backups, software distribution
    Password protection Built-in (-e flag) Requires gpg separately

    Widely cited Linux performance community benchmarks show tar.gz consistently outperforms zip on compression ratio for source code and log files, typically by 5-10 percentage points. For anything you are sending to a Windows user, zip wins on convenience every time.

    If you are studying for OSCP, working through CTF challenges, or preparing for placements at Indian IT companies like Infosys, TCS, or Wipro where Linux server skills are tested, knowing both formats is non-negotiable. The Kali Linux beginner commands guide at 3.0 University gives you a broader picture of the terminal skills that sit alongside file compression.

    Quick command reference

    Task Command
    Zip a folder zip -r output.zip folder/
    Unzip a file in Linux unzip archive.zip
    Unzip to specific folder unzip archive.zip -d /path/
    Create tar.gz tar -czvf archive.tar.gz folder/
    Extract tar.gz file in Linux tar -xzvf archive.tar.gz
    Extract tar.gz to folder tar -xzvf archive.tar.gz -C /path/
    Open a .gz file gunzip filename.gz
    Open a .tgz file tar -xzvf filename.tgz
    Extract .tar.bz2 tar -xjvf archive.tar.bz2
    Extract .tar.xz tar -xJvf archive.tar.xz
    List zip contents unzip -l archive.zip
    List tar.gz contents tar -tzvf archive.tar.gz

    Practice these on any Linux VM or on a free tier AWS EC2 instance. If you are a student at IIT, NIT, or working through a CDAC course, your lab environment almost certainly has bash access, and these commands work identically across all distributions including Ubuntu, CentOS, and Kali Linux.

    The practical reality is that unzipping a file in Linux takes one command. Extracting a tar.gz file takes one command. The only thing stopping most beginners is not knowing the flags, and now you do. Put these commands into a cheat sheet, run them a few times on dummy files, and they will stick permanently.

    Head to 3.0 University’s practical tech labs to work through hands-on Linux exercises in a structured environment where you practice these commands alongside networking, scripting, and security fundamentals.

    Frequently Asked Questions

    How do you unzip a file in Linux?

    Run unzip filename.zip in your terminal. This extracts all contents into the current directory. To extract into a specific folder, add the -d flag: unzip filename.zip -d /target/folder/. If unzip is not installed, run sudo apt install unzip on Ubuntu or Debian, or sudo dnf install unzip on Fedora. The command works identically on all major Linux distributions.

    How do you check if unzip is installed in Linux?

    Run which unzip or unzip –version in your terminal. If the command returns a path like /usr/bin/unzip or a version number, it is installed. If you see a “command not found” error, install it with sudo apt install unzip on Ubuntu or Debian-based systems, or sudo dnf install unzip on Fedora and RHEL-based systems including those used in CDAC and enterprise Indian IT environments.

    How do you zip a folder in Linux?

    Use zip -r archive.zip foldername/. The -r flag is essential because it tells zip to recurse into subdirectories. Without it, zip only processes files at the top level and silently ignores everything inside nested folders. To add maximum compression, combine flags: zip -9 -r archive.zip foldername/. Install zip first with sudo apt install zip if needed.

    How do you extract a tar.gz file in Linux?

    Run tar -xzvf filename.tar.gz. The flags mean: x=extract, z=gzip, v=verbose, f=filename. To extract into a specific directory instead of the current one, use the -C flag: tar -xzvf filename.tar.gz -C /destination/. You can preview the archive contents without extracting using tar -tzvf filename.tar.gz. No additional software installation is needed; tar is built into Linux.

    How do you untar a .gz file in Linux?

    The same command handles both untarring and decompressing: tar -xzvf filename.tar.gz. Tar automatically detects gzip compression when the -z flag is present and handles both steps in one pass. If you have a plain .gz file that is not a tar archive, use gunzip filename.gz instead. That decompresses the single file in place.

    How do you open a .tgz file in Linux?

    Run tar -xzvf filename.tgz. A .tgz file is identical to a .tar.gz file; it is just a shortened extension. Tar recognises both formats with the same flags. To extract into a specific folder: tar -xzvf filename.tgz -C /path/to/folder/. You will frequently encounter .tgz files when downloading older open-source software or academic datasets distributed via FTP servers, including those hosted by Indian government and university portals.

    Last updated: July 2026. Reviewed by the 3University editorial team.

    • Share:
    3.0 University

    Previous post

    Linux File Permissions Explained: chmod, chown and Practical Examples
    July 13, 2026

    Next post

    ISRO Free Online Courses with Certificate: Apply Online & Get Certified
    July 13, 2026

    You may also like

    Free AI Certificate Course by Government of India
    FREE AI Course with Certificate Launched by Govt of India
    June 19, 2026
    Highest Paid Professions in India
    Highest Paid Profession in India
    June 12, 2026
    Cyber Security Course Eligibility
    Cyber Security Course Eligibility
    June 11, 2026

    Leave A Reply Cancel reply

    You must be logged in to post a comment.

    3.0 University is a pioneering academic initiative for creating a comprehensive knowledge ecosystem for emerging technologies. We have developed an in-house suite of course offerings for retail, institutional market participants and industry-at-large. 

    Facebook X-twitter Instagram Linkedin
    Quick Links
    • About us
    • Courses
    • Become a Partner
    • Contact Us
    • Blog
    • Learn
    Trending Courses
    • Certified SOC Analyst
    • Certified Ethical Hacker v13 Program
    • Certified Penitration Testing Professional
    • Full Stack Blockchain Developer
    • Certified AI Program Manager
    Policies
    • Privacy Policy
    • Terms and Conditions
    • Disclaimer
    • Refund Policy
    Contact Us
    FT Tower, CTS No. 256 & 257,
    Suren Road, Chakala, Andheri (E), Mumbai-400093 India.

    +91 8657961141

    support@3university.io

    Login with your site account

    Lost your password?

    Not a member yet? Register now

    Register a new account

    Are you a member? Login now

    Login with your site account

    Lost your password?

    Not a member yet? Register now

    Register a new account

    Are you a member? Login now

    Sign In

    Welcome back! Or create an account

    OR
    Forgot password?

    Need a new verification email?

    Don't have an account? Register

    Create Account

    Already have an account? Sign in

    OR

    Already have an account? Log in

    Reset Password

    Enter your email and we'll send you a reset link.

    ← Back to login

    Check Your Email

    Almost there!
    We have sent a verification link to your email address. Please check your inbox (and spam folder) and click the link to activate your account.

    Didn't receive the email? Enter your address to resend:

    Already verified? Sign in