[email protected]Office hours: Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedOctober 10, 2023

How to Extract (Unarchive) Files with Tar, Untar, and Gzip commands.

How To Extract (Unarchive) Files With Tar, Untar, And Gzip Commands.

In Linux and Unix-like operating systems, the tar command is used to create and manipulate archive files, and gzip is a common compression tool. To extract or unarchive files from a compressed tar.gz archive, follow these steps:

Step 1: Navigate to the Directory

Open your terminal and navigate to the directory where the tar.gz archive is located. You can use the cd command to change directories.

cd /path/to/your/archive_directory

 

Step 2: Use Tar to Extract the Archive

To extract the contents of the tar.gz archive, you’ll first use tar with the -xzf options. The -x option tells tar to extract files, the -z option specifies gzip compression, and the -f option indicates the archive file name.

tar -xzf archive.tar.gz

This command will extract the files from the archive while preserving their directory structure.

 

Step 3: View the Extracted Files (Optional)

If you want to see a list of the extracted files, you can use the ls command in the same directory where you extracted the files.

ls

This will display the names of the files and directories that were extracted.

 

Step 4: Complete the Extraction

Now, you have successfully extracted the contents of the tar.gz archive. You can access and use these files as needed.

 

Additional Tips:

  1. Extracting to a Specific Directory: By default, tar extracts files to the current working directory. If you want to extract the files to a specific directory, use the -C option followed by the directory path. For example:

    tar -xzf archive.tar.gz -C /path/to/destination
  2. Preserving File Permissions: When extracting files with tar, it preserves file permissions by default. This ensures that the extracted files have the same ownership and permissions as the original files.

  3. Handling Different Compression Formats: While gzip is a common compression tool, Linux supports various compression formats. You can extract files from .tar.bz2 archives using tar -xjf, and from .tar.xz archives using tar -xJf. Replace j with z for gzip compression and J for LZMA compression.

  4. Verbose Output: To see a detailed list of files as they are being extracted, add the -v (verbose) option to the tar command:

    tar -xvzf archive.tar.gz
  5. Extracting Specific Files: If you only want to extract specific files from the archive, list their names after the archive file. For example:

    tar -xzf archive.tar.gz file1.txt file2.txt
  6. Using Wildcards: You can use wildcards to extract files that match a specific pattern. For instance, to extract all .txt files, you can use:

    tar -xzf archive.tar.gz --wildcards '*.txt'
  7. Deleting the Archive: After extracting the files, you may want to remove the original tar.gz archive. You can do this using the rm command:

    rm archive.tar.gz

 

Additional Note:

The process outlined here is a common and essential operation for managing files on Linux and Unix-based systems. Whether you’re working with software installations, backups, or data transfer, knowing how to create, extract, and manage archive files is a valuable skill.

Keep reading
How to Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, colocation, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Office hours: Mon – Fri 9:00AM – 5:00PM