• A tarball -TAR or TAR.GZ- is a collection of grouped files that facilitates storage
  • The main advantage is that you will be able to extract only the file that you need, and not all of them.
  • What are the steps to follow to extract or delete TAR files and folders?

There are different elements that are essential for the operation of the Windows operating system and to which, however, we are not so used. If you come across these types of items, you probably don’t know what to do with them. That’s why we invite you to discover how to extract an archive from a TAR file and use it on your computer.

The first thing you should know is that a tarball -TAR or TAR.GZ- is a collection of files grouped into one, making it easy to store and transfer large amounts of files locally or over the Internet. Whenever you need to access the internal files, you will need to unzip the files.

To give an example, let’s think about those cases in which you need a single file in a large file. Forget about unzipping the entire file because the advantage is that you will to be able to extract only what you need.

If you still do not fully understand how these files/archives work, we will review it in the following article.

YOU CAN ALSO READ:   How to Fix Steam Error Code 118

How to view and extract Tarball contents?

View Tarball Content

To see the contents of a TAR or TAR.GZ file you don’t need to extract the file but just run this command:

tar -tvf [archivo.tar] tar -ztvf [archivo.tar.gz]

Automatically, that will print a list of all the files and folders inside the file.

This will print a list of all files and folders within the archive.

extract file tar file 2

Extract a tarball file

Instead, if you’re sure you want to extract an archive from the TAR or TAR.GZ file, run this command:

tar -xvf [archivo.tar] [ruta al archivo] tar -zxvf [archivo.tar.gz] [ruta al archivo]

Remember that you have to provide the full path to the file you want to extract in order to access it. You can always find the full path of a file or directory with the command tar -tvf [archive.tar

Citando un caso común, para extraer el archivo test1.txt de los archivos test.tar y test.tar.gz, los comandos serían:

tar -xvf prueba.tar prueba1.txt tar -zxvf prueba.tar.gz prueba1.txt

En ese supuesto, si analizamos un poco nos topamos con que funcionan así:

  • x se usa para extraer archivos del archivo
  • v se usa para ver el progreso a medida que se extraen
  • f se utiliza para especificar el nombre tarball
  • z se usa para extraer el archivo TAR.GZ

Estos comandos extraerán el archivo especificado en el directorio del terminal actual en unos segundos.

extraer archivo fichero TAR 3

Extraer una carpeta de Tarball

De forma similar, también puedes extraer un directorio de un tarball usando el siguiente comando:

tar xvf [archivo.tar] [ruta al directorio] tar -zxvf [archivo.tar.gz] [ruta al directorio]

To extract the entire test1 subdirectory of the test.tar file, you must provide the directory path, like so:

YOU CAN ALSO READ:   How to calculate CAGR in Microsoft Excel?

tar -xvf test.tar test/test1

This will unzip the entire test/test1 subdirectory into the current terminal directory.

extract file tar file 4

Extract a file or folder to another folder

You can extract a file or a folder to another folder, complementing the previous syntax with the -C option followed by the destination directory, as we are going to show you next, obtaining this specific command:

tar -xvf [archivo.tar] -C [destino] [archivo o directorio] tar -zxvf [archivo.tar.gz] -C [destino] [archivo o directorio]

Assuming you want to extract a test2 folder from the test.tar file to the Downloads folder, it would look like this:

tar -xvf test.tar -C ~/Downloads/test/test2

Delete a file or folder from tarball

If you need to remove a file or directory from a TAR or TAR.GZ archive, use the –delete option with the tar command:

tar -vf [archivo.tar] –delete [archivo o directorio]

However, you cannot delete files or folders directly from the compressed tarball TAR.GZ. You have to first extract the TAR.GZ file, delete the file or folder, and then extract it again.

To extract the TAR.GZ file, use the following command:

gzip -d [archivo.tar.gz]

Extracting it will convert the archive to TAR to remove files from the TAR archive using:

tar -vf [archivo.tar] –delete [archivo o directorio]

After that, extract the tar file with gzip

gzip -f [archivo.tar]

It’s a bit more difficult, but you can delete a file or folder if you want to.

Conclusions and recommendations

Extracting only the necessary files from an archive not only avoids clutter, but also saves time that would otherwise be wasted searching through a large number of extracted files without any logic.

YOU CAN ALSO READ:   How to wrap text around a table in Word

Sometimes creating and decompressing TAR archives leads to duplicate files on the system and you have to be aware of it. You should take the trouble to periodically identify and remove those duplicates to free up disk space.

Do you usually use TAR files in your day to day? What else would you like to know about this class of elements?

Write A Comment