Compresión Bajo Linux

Friday September 09, 2005 (07:01 PM GMT)

By: Shashank Sharma

Among the confusion new Linux users often face is the variability among archived and compressed formats used by downloaded applications. “Should I use the tar.gz file, the zip file, or the tar.bz2 file?” they may wonder. Here’s what you need to know about compression formats in order to easily install any application.

First, consider the distinction between archiving and compression. Archiving means combining a number of files together into one file. The idea is to achieve easier storage and transportation. It’s like having a briefcase in which to keep all your files. The archive must contain some information about the original files, such as their names and lengths, for proper reconstruction. This ensures that your paperwork will remain as-is when you open your briefcase. Some popular archive file formats are tar and zip.

Compression, on the other hand, is the process of using encoding schemes to store information in fewer bits than traditional representation would use. It’s similar to the difference between shorthand writing and normal writing, where the former requires less paper than the latter. Common compression formats are zip, gz, and bz2.

Working with archives

The tar format is the most common archive format on *nix systems. Tar was originally designed for transferring files to and from tape drives — its name is short for “tape archive.” A tar archive is commonly called a tarball.

To archive files, use a command like tar -cf archive.tar file1 file2 file3. This command combines file1, file2, and file3 and stores them in archive.tar. The -c switch tells tar that you want to create an archive. The -f switch indicates that we are working on files.

The command tar -xf archive.tar extracts all the files from archive.tar and stores them in the current directory with their original names.

Compressing files

In *nix land, bz and gz are two of the most common compression formats. Typically you use the bzip2 utility to create bz files and gzip to create gz. The fundamental difference is in the compression algorithm used by bzip2, which results in considerably smaller files. The downside is that bzip2 eats up more memory.

To compress a file using gzip, use the command gzip filename . The result is a file named filename.gz. Thus the command gzip homepage.htm yields homepage.htm.gz.

One thing to remember about gzip is that it replaces the original file with one which has .gz extension.

To uncompress files, use either gzip -d or gunzip.

bzip2 is similar to gzip. As with gzip, bzip2 also overwrites the original file with one which has a .bz or .bz2 extension. Decompressing .bz files is a breeze — use bzip2 -d or bunzip2.

Both gzip and bzip2 maintain the ownership and permissions of the original file when compressing.

You can also use the zip utility to compress files, if you wish to share files with friends who use a non-*nix platform. zip files.zip file1 file2 file3 would compress the three files, display the rate of compression of each file, and store them in files.zip. The unzip program can be used to extract the contents of a zip file.

Compressed archives

Unlike zip, which offers compression and archiving functionality, tar is capable of archiving only. This means that after you create a tarball, its size is the same as the cumulative size of the individual files. To reduce the size of a tarball, you must compress it by using either gzip or bzip2:

tar -cf archived.tar file1 file2 file3
gzip archived.tar

This compresses archived.tar and replaces it with archived.tar.gz. You could also use bzip2 instead of gzip.

How do you extracting files from a compressed tarball? Use tar zxvf archived.tar.gz to extract all the files from a gzip-compressed tarball. The z switch tells tar that the tarball was compressed using gzip.

If you used bzip2 to compress this tarball, you’d get an error message if you used tar’s z switch. To decompress a bzip2-compressed tarball, you need to use the j switch in its place. tar jxvf archived.tar.bz would extract the files.

You may encounter compressed tarballs in other formats, such as tgz and tbz2. These are short for tar.gz and tar.bz2, respectively.

Though it may seem complex at first, that’s all there is to archiving and compression under *nix. From here on, no matter what compression format you encounter, you’ll know what you need to do.

One Commentto Compresión Bajo Linux

  1. Banned Chipola dice:

    Viernes Septiembre 09, 2005 (07:01 PM GMT)

    Resumen en español.

    Entre las confusiones que los nuevos usuarios de Linux enfrentan se encuentra la variedad de archivos y formatos de compresion a usar.

    Primero, considere la distincion entre archivamiento y compresion. Archivamiento significa juntar un numero de archivos en uno solo. La idea de archivamiento es un transporte y almacenamiento mas sencillo. Algunos formatos populares de archivamiento son tar y zip.

    Por otro lado compresson, es el proceso de codificar esquemas para almacenar informacion en una menor cantidad de bits que su representacion tradicional pueda llegar a usar.Los formatos de compresion comunes son zip, gz, and bz2.

    Trabajando con archivamiento.

    El archivo tar, este nombre es una abreviatura de Tape ARchive es llamado comunmente tarball. Para archivar con tar se usa el comando:

    tar -cf archivo.tar archivo1 archivo2 archivo3.

    archivo1 2 y 3 son los archivos a combinar en archivo.tar. El modificador -c indica al comando que quiere crear un archivo, el modificador -f indica que se esta trabajando con archivos.

    El comando tar -xk archivo.tar extrae los archivos de archivo.tar y los coloca en su correspondiente directorio con sus nombres originales.

    Comprimiendo archivos.

    Hay dos programas basicos de compresion en linuz, bzip2 y gzip. bzip2, usa un algoritmo que da como resultado archivos mas pequeños, pero tiene en contra que consume mas recursos al realizar esa compresion

    Para comprimir un archivo usando gzip: gzip nombrearchivo. El resultado es un archivo llamado nombrearchivo.gz. Asi por lo tanto, homepage.htm quedara homepage.htm.gz

    Una cosa a recordar acerca de gzip es que reemplaza al archivo original con uno con extensión gz

    Para descomprimir archivos, se usa gzip -d o gunzip

    bzip2 es un poco similar. bzip2 también sobreescribe el archivo original con uno con extensión .bz o .bz2 para descomprimir archivos se usa bzip2 -d o bunzip2.

    gzip and bzip2 mantienen originales del archivo los permisos y derechos del propietario al comprimir.

    También puede usarse la utilidad zip para compresión. Si desea compartir archivos con sus conocidos que no usan una plataforma linux el archivo1 archivo2 y archivo3 pueden comprimirse en un solo archivo.zip. El programa unzip se usa para extraer los contenidos de dicho archivo.

    Archivos comprimidos.

    Zip, ofrece compresion y archivamiento, tar solo es capaz de archivamiento. Esto significa que despues de crear un tarball, el tamaño de cada archivo queda igual. Para reducir el tamaño de un tarball se usa el comando gzip o bzip2

    tar -cf archivo.tar arch1 arch2 arch3
    gzip archivo.tar

    Asi se comprime archivo.tar y es reemplazado con archivo.tar.gz Tambien se puede usar bzip2

    ¿Cómo se puede descomprimir estos archivos?
    Use tar zxvf archivo.tar.gz para extraer todos los archivos de un tarball comprimido con gzip. El modificador z indica que el archivo a descomprimir es gzip .

    Para descomprimir un tarball bzip2 use el modificador j.
    tar jxvf archivo.tar.bz

    Puede encontrar tarballs con otras extensiones, tales como tgz y tbz2, estos son abreviaturas de tar.gz y tar.bz2

    Puede parecer complicado al principio, pero es todo lo que necesita para el archivamiento y la compresion bajo linux. Desde ahora, no importa el formato de compresión con el que se encuentre, ya sabra que hacer.