Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Traduccion de todo

Table of Contents
maxLevel3
stylesquare

This article will help you understand how you can handle the common file formats El propósito principal de este articulo es asistir en la comprensión de como manejar los formatos de archivo mas comunes como TAR, GZIP, BZIP and ZIP on Linux operating systems (including CentOS, Ubuntu) and even some Unix-based OSes like MacOS (OS X) via the command line either via SSH or a local terminal session.

How to Install the Needed Tools

On many Linux-like operating systems the command line tools for working with TAR, GZIP, BZIP and ZIP files are already installed, so you almost certainly don't need to install anything, but if you are running a minimal installation of your OS or if you've removed the tools in the past, follow the directions below to install what you need. Select the tab for the OS you are running:

Working with TAR Files

The TAR file format is a very early archiving format that doesn't include any active compression by default. Often on Linux, items are tarred and then gzipped to compress them. TAR files typically end in .tar.

Put a Directory into a TAR File

, y ZIP en sistemas operativos Linux, incluyendo CentOS, Ubuntu y sistemas operativos basados en Unix como MacOS, incluyendo OS X por medio de la linea de comandos, ya sea una sesión de terminal local o vía SSH.

Como instalar las herramientas necesarias

Muchos sistemas operativos similares a Linux ya cuentan con las herramientas necesarias para manipular archivos TAR, GZIP, BZIP, sin embargo, en el caso de no contar con dichas herramientas ya sea por utilizar una versión mínima del SO o si removió las herramientas en el pasado, puede proceder con los siguientes pasos. Seleccione la pestaña de acuerdo al sistema operativo que esta utilizando.



Utilizando archivos TAR

El formato de archivos TAR es un formato de almacenamiento que no incluye compresión activa por defecto. Usualmente en Linux los elementos son agregados a un mismo archivo y posteriormente comprimidos con gzip. La extensión de los archivos TAR es .tar

Colocar un directorio en un archivo TAR

Ejecute lo siguiente para crear un archivo .tar que contenga los elementos del directorio especificadoExecute the following to create a single .tar file containing all of the contents of the specified directory:

Code Block
tar cvf FILENAMENOMBREDEARCHIVO.tar DIRECTORY/

Replace FILENAME with whatever filename you want and DIRECTORY with the path to the directory you want to make into a tarball.

Command Flags Explanation

c: Create a TAR file.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename for the resulting TAR file.

Put a Directory into a TAR file and Compress it with GZIP

DIRECTORIO/

Reemplace NOMBREDEARCHIVO con el nombre de archivo que desea y DIRECTORIO con la ruta del directorio que desea comprimir. 

Descripción de las banderas de comando

c: Crea un archivo TAR.
v: Muestra detalladamente (Señala detalladamente que esta pasando).
f: Especifica un nombre de archivo para el archivo TAR resultante.

Colocar un directorio en un archivo TAR y comprimirlo con GZIP

Ejecute lo siguiente para crear un archivo .tar.gz que contenga los elementos del directorio especificadoExecute the following to create a single .tar.gz file containing all of the contents of the specified directory:

Code Block
tar cvfz FILENAMENOMBREDEARCHIVO.tar.gz DIRECTORY/

Replace FILENAME with whatever filename you want and DIRECTORY with the path to the directory you want to make into a compressed tarball.

Info

Tarred files compressed with GZIP sometimes use the .tgz file extension.

Command Flags Explanation

c: Create a TAR file.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename for the resulting TAR file.
z: Compress the TAR file with GZIP

Put a Directory into a TAR file and Compress it with BZIP2

DIRECTORIO/

Reemplace NOMBREDEARCHIVO con el nombre de archivo que desea y DIRECTORIO con la ruta del directorio que desea comprimir.

Info

Algunos archivos comprimidos con GZIP utilizan la extensión de archivo .tgz

Descripción de las banderas de comando

c: Crea un archivo TAR.
v: Muestra detalladamente (Señala detalladamente que esta pasando).
f: Especifica un nombre de archivo para el archivo TAR resultante.
z: Comprime el archivo TAR con GZIP.

Colocar un directorio en un archivo TAR y comprimirlo con BZIP2

Ejecute lo siguiente para crear un archivo .tar.bz2 que contenga los elementos del directorio especificado comprimido con BZIP. (La diferencia de GZIP y BZIP es que este ultimo crea archivos mas pequeños a cambio de mas tiempo de procesamientoExecute the following to create a single .tar.bz2 file containing all of the contents of the specified directory compressed with BZIP. (BZIP typically produces smaller files than GZIP, at the cost of more processing time.):

Code Block
tar cvfj FILENAMENOMBREDEARCHIVO.tar.bz2 DIRECTORY/

Replace FILENAME with whatever filename you want and DIRECTORY with the path to the directory you want to make into a compressed tarball.

Command Flags Explanation

c: Create a TAR file.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename for the resulting TAR file.
j: Compress the TAR file with BZIP2

Extract Items from TAR Files

DIRECTORIO/

Reemplace NOMBREDEARCHIVO con el nombre de archivo que desea y DIRECTORIO con la ruta del directorio que desea comprimir.

Descripción de las banderas de comando

c: Crea un archivo TAR.
v: Muestra detalladamente (Señala detalladamente que esta pasando).
f: Especifica un nombre de archivo para el archivo TAR resultante.
j: Comprime el archivo TAR con BZIP2.

Extraer elementos de archivos TAR

Ejecute el siguiente comando para extraer archivos y directorios de un archivo .tar comprimidoExecute the following command to extract files and directories from an uncompressed .tar file:

Code Block
tar xvf FILEARCHIVO.tar

Replace FILE with the filename of the file you are trying to uncompress. The file will uncompress into the current directory.

Command Flags Explanation

x: Extract the contents from the file specified.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename to uncompress.

Extract Items from GZIPPED Tarball File

Reemplaza ARCHIVO con el nombre de archivo del archivo que desea descomprimir. El archivo aparecerá en el directorio actual.

Descripción de las banderas de comando

x: Extrae el contenido del archivo especificado.
v: Muestra detalladamente (Señala detalladamente que esta pasando).
f: Especifica un nombre de archivo para descomprimir.

Extraer elementos de archivos GZIPPED TAR

Ejecute el siguiente comando para extraer archivos y directorios de archivos TAR comprimidos en GZIPExecute the following command to extract files and directories from a GZIP compressed TAR file:

Code Block
tar xvfz FILEARCHIVO.tar.gz

Replace FILE with the filename of the file you are trying to uncompress. The file will uncompress into the current directory.

Command Flags Explanation

x: Extract the contents from the file specified.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename to uncompress.
z: Uncompress the tarball via GZIP.

Extract Items from BZIPPED Tarball File

Reemplaza ARCHIVO con el nombre de archivo del archivo que desea descomprimir. El archivo aparecerá en el directorio actual.

Descripción de las banderas de comando

x: Extrae el contenido del archivo especificado.
v: Muestra detalladamente (Señala detalladamente que esta pasando).
f: Especifica un nombre de archivo para descomprimir.
z: Descomprime el archivo vía GZIP.

Extraer elementos de archivos BZIPPED TAR

Ejecute el siguiente comando para extraer archivos y directorios de un archivo TAR comprimido en BZIPExecute the following command to extract files and directories from a BZIP compressed TAR file:

Code Block
tar xvfj FILEARCHIVO.tar.bz2

Replace FILE with the filename of the file you are trying to uncompress. The file will uncompress into the current directory.

Command Flags Explanation

x: Extract the contents from the file specified.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename to uncompress.
j: Uncompress the tarball via BZIP2.

Tip

If you'd rather specify a different directory to extract files to rather than just dumping everything in the current directory add -C /PATH/TO/DIRECTORY/ to the commands above. Replace /PATH/TO/DIRECTORY/ with the actual path to the directory where you want the files to be placed.

Working with Zip Files

Zip is probably the most common compressed archiving format in the world. Zip files usually end in .zip.

Compress a Directory Full of Files into a ZIP File

Reemplaza ARCHIVO con el nombre de archivo del archivo que desea descomprimir. El archivo aparecerá en el directorio actual.

Descripción de las banderas de comando

x: Extrae el contenido del archivo especificado.
v: Muestra detalladamente (Señala detalladamente que esta pasando).
f: Especifica un nombre de archivo para descomprimir.
j: Descomprime el archivo vía BZIP2.


Tip

Si desea utilizar otro directorio para extraer los archivos en lugar de utilizar el directorio actual, puede agregar -C /RUTA/AL/DIRECTORIO/ a la linea de comandos. Reemplace /RUTA/AL/DIRECTORIO/ con la ruta actual al directorio donde desea que los archivos sean colocados.


Utilizando archivos ZIP

Zip es el formato de compresión de archivos mas popular. Los archivos Zip usualmente tienen la extensión .zip

Comprimir un directorio en un archivo ZIP

Ejecute el siguiente comando para colocar los archivos de un directorio especifico en un archivo ZIP comprimidoExecute the following command to place everything inside a specified directory into a compressed ZIP file.

Code Block
zip -r FILEARCHIVO.zip DIRECTORYDIRECTORIO/

...

Descripción de las banderas de comando

-r: Recursively compress all files and directories contained within DIRECTORY/ in the zip file (otherwise you only get the top level files).

Uncompress a ZIP file Into the Current Directory

Comprime todos los archivos y directorios de manera recursiva que estén dentro de DIRECTORIO/ en el archivo ZIP (de otra forma solo se comprimirán los archivos externos).

Descomprimir un archivo ZIP en el Directorio actual

Ejecute el siguiente comando para descomprimir los elementos del archivo ZIP en el directorio actualExecute the following command to uncompress the items in the ZIP file into the current directory.

Code Block
unzip FILEARCHIVO.zip