How to extract files in linux

How To Extract Zip, Gz, Tar, Bz2, 7z, Xz, and Rar Files in Linux

Linux, the open-source operating system, is favored by many for its flexibility, power, and robustness. It offers a vast array of tools that can handle a multitude of tasks, including working with compressed files. In this comprehensive guide, we will walk you through the process of extracting various file formats like Zip, Gz, Tar, Bz2, 7z, Xz, and Rar in Linux.

1. Extracting ZIP Files

ZIP is one of the most commonly used file formats for compression. To extract a ZIP file in Linux, you will need the unzip command. If it’s not already installed, you can install it using the package manager of your distribution. For example, on Ubuntu, you can install unzip with:

sudo apt-get install unzip 

To extract a ZIP file, use the following command:

2. Extracting TAR Files

TAR (short for Tape Archive) is a widely used archive format in Linux. To extract TAR files, use the tar command followed by the options -xvf (x: extract, v: verbose, f: file):

3. Extracting GZ Files

GZ, or gzip, is a file format and a software application used for file compression and decompression. The gunzip command is used for extracting these files. Here is an example:

To exract a tar.gz file, type:

4. Extracting BZ2 Files

BZ2 is a high-quality data compressor used for compressing and decompressing files. To extract a BZ2 file, use the bunzip2 or bzip2 -d command:

To exract a tar.bz2 file, type:

5. Extracting 7Z Files

7Z is a file format that provides a high compression ratio. It’s used with the 7-Zip software, but Linux users can extract it using the p7zip tool. If it’s not installed, install it with:

sudo apt-get install p7zip-full 

Then, you can extract a 7Z file with:

6. Extracting XZ Files

XZ is a high-quality compression algorithm and file format. To extract XZ files in Linux, use the unxz command or xz -d:

7. Extracting RAR Files

RAR is a proprietary archive file format that supports data compression, error recovery, and file spanning. To extract RAR files, you need to install the unrar package first:

sudo apt-get install unrar 

Then, use the following command to extract a RAR file:

Читайте также:  Linux rename directory command

Conclusion

Working with compressed files is a common task in Linux. Understanding how to extract various file formats is an essential skill for any Linux user. This guide has provided you with detailed instructions on how to extract Zip, Gz, Tar, Bz2, 7z, Xz, and Rar files.

Remember, Linux commands can vary slightly depending on your specific distribution and its package manager, so always refer to the appropriate documentation or man pages (man command_name) for the most accurate information.

Master these commands, and you will find managing compressed files in Linux a breeze!

Источник

How to Extract or Unzip tar.gz Files from Linux Command Line

A tar.gz file contains several compressed files to save storage space, as well as bandwidth during the downloading process. The .tar file acts as a portable container for other files and is sometimes called a tarball. The .gz part of the extension, stands for gzip, a commonly-used compression utility.

In this guide you will learn how to extract or unzip files from tar.gz files using command-line in Linux.

tutorial on extracting files using tar.gz from command line

  • Access to a command-line/terminal window
  • The tar utility (included by default)
  • The gzip utility (included by default)

Extracting tar.gz Files in Linux

Using gzip Utility

Gzip by default, extracts the file in the current directory. In this example the file is located in the Documents directory.

Below, we have used the file named test.txt. Use the name of the file you want to compress instead.

to compress a single file with gzip enter the command in your terminal window:

After zipping the file, enter the command ls to confirm that the file has been compressed. The output confirms that the file now has a .gz extension.

confirming that the file has been compressed

To decompress a file, use the gunzip command:

Again, use the ls command to confirm the extension of the file.

example file has been unzipped

To compress all the .txt files in a particular directory, type in:

The * sign is a wildcard, which means “any number of any characters.” This command would work on any (and all) filenames with the extension .txt.

This technique can be used on other file types including gzip.txt, .jpg, and .doc.

When you run gzip on multiple files at once, the system generates a compressed copy of each file. This can clutter up a directory quickly! Fortunately, there’s another tool to manage multiple files at once.

Using tar Utility

A tar.gz file is a combination of a .tar file and a .gz file. It is an archive file with several other files inside it, which is then compressed.

You can unzip these files the same way you would unzip a regular zipped file:

output in the linux terminal when extracting a tar.gz file

The basic command is tar , followed by four options:

  • x – instructs tar to extract the files from the zipped file
  • v – means verbose, or to list out the files it’s extracting
  • z – instructs tar to decompress the files – without this, you’d have a folder full of compressed files
  • f – tells tar the filename you want it to work on
Читайте также:  Oracle linux network manager

To list the contents of a .tar file before you extract it, enter:

To instruct tar to put the extracted unzipped files into a specific directory, enter:

tar –xvzf documents.tar.gz –C /home/user/destination

how to unzip a tar.gz file to a specific destination in Linux

To create a tar.gz file, use the following command:

tar –cvzf documents.tar.gz ~/Documents

Similar to the tar command, it condenses all the content located in the /home/user/Documents directory into a single file, called documents.tar.gz. The addition of the –z option is what signals tar to compress the files.

To add multiple files to a tar file, use the command:

tar -cvf documents.tar ~/Documents

This copies the contents of your Documents folder into a single file, called documents.tar. The options -cvf work as follows:

  • c – creates a new archive
  • v – verbose, meaning it lists the files it includes
  • f – specifies the name of the file

To extract the files from a .tar file, enter:

This command extracts and lists all files from the documents.tar file. The -x option tells tar to extract the files.

Command that extracts all files from a zipped document

You can also use xargs with tar to create a tar.gz archive and populate it with files from the find command.

Note: Some graphical interfaces include a tool for managing tar.gz files without the command-line. Simply right-click the item you want to compress, mouseover compress, and choose tar.gz. You can also right-click a tar.gz file, mouseover extract, and select an option to unpack the archive.

This tutorial explains how to use the tar tool, the gzip tool, and how to utilize them together to work with tar.gz files. You are now ready to extract or unzip any tar.gz file.

Источник

How to extract the file on Linux [Command line]

Tutorial Unzip A Zip File In Linux With 7 Different Methods

As you know, the most popular and widely used compression formats today are zip, tar.gz, and rar. Zip is an archive file format that contains one or more compressed directories. It supports lossless data compression. Today we are with you with the tutorial on How to Unzip A Zip File In Linux With 7 Different Methods. If you want to buy a Linux VPS server, you can visit the services available in Eldernode.

How to Unzip A Zip File In Linux With 7 Different Methods

Compression and extraction are one of the most important tasks used in any operating system. If you have used Windows for this, you will notice the ease of work, but in Linux, it is a little different. For example, if you want to extract a compressed file, you can graphically enter the folder or right-click and extract. But there are times when you have no graphical access at all. So you should be able to extract the file or compress the file through the terminal and command.

Unzip a Zip File in Linux using Linux Terminal

First, install the Unzip package with the following command:

Note that some Linux distributions have the unzip package by default and you don’t need to install it.

Читайте также:  Linux and home automation

In this step, you need to navigate to the ZIP file. To do this enter the following command:

Now it’s time to unzip a zip file. If you want to unzip the zip file to the current directory run the command below:

But if you want to unzip the zip file to a different directory, just use the following command:

unzip your-file.zip -d directory

How to compress and extract a ZIP file in Linux

Unzip a Zip File in Linux using Python

You can unzip a zip file using Python scripting language which contains all the necessary modules. To do this enter the following command:

#!/usr/bin/env python3 import sys from zipfile import PyZipFile for zip_file in sys.argv[1:]: pzf = PyZipFile(zip_file) pzf.extractall()

Now enter the command below to unzip the zip file:

python3 pyunzip.py master.zip

Unzip a Zip File in Linux using Perl

Perl scripting language can unzip the zip file on Linux. First, enter the following script:

#!/usr/bin/env perl use Archive::Extract; foreach my $filepath (@ARGV)< my $archive = Archive::Extract->new( archive => $filepath ); $archive->extract; >

Run the command below to unzip the zip file:

perl perlunzip.pl master.zip

Unzip a Zip File in Linux using Bzip2

You can unzip the zip file in Linux easily with Bzip2 using the following command:

bzip2 -kvd testfile1.txt.bz2 testfile2.txt.bz2

To get Bzip2 options, enter the command below:

Unzip a Zip File in Linux using Tar

All you have to do is enter the following command:

tar -xzvf Documents.tgz Documents

The xzvf options break down as x for extract, z for unzipping with gzip, v for verbose, and f for file means to keep the file structure.

You can view the tar options with the following command:

Unzip a Zip File in Linux using Linux GUI

In the first step, you should find the zipped archive and right-click on it. Choose Extract Here from the among options. If you want to put the contents somewhere else, you can choose Extract to:

Unzip-zip-file-Linux-GUI

The files will be extracted.

Unzip a Zip File using Archive Manager in the Linux GUI

Some Linux distributions have an archive manager to unzip a zip file.

Right-click on the zipped file and choose Open With Archive Manager:

Unzip-open-with-archive-manager

Now click on the files you want to extract to highlight them and click on Extract:

Unzip-highlight-files

Choose where you want to extract the file and click on Extract:

Location-of-zipfiles

Conclusion

Unzipping files is one of the most important tasks used in any operating system, especially the Linux operating system. In this tutorial, we tried to learn you how to compress and extract zip, tar, tar.gz files, and extract RAR files. In this article, we taught you How to Unzip A Zip File In Linux With 7 Different Methods. If you have any questions or suggestions, you can contact us in the Comments section. I hope this tutorial was useful for you.

Click on a star to rate it!

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Источник

Оцените статью
Adblock
detector