Tutorial VPS Centos How to use Gzip, Zip, and Tar

Tutorial Centos how to manage File Compression and Archiving with Gzip, Zip, and Tar? to use this its easy. so what function compression or archiving file? this is very usefull to make more space free. Compressed files use less disk space and download faster than large, uncompressed files. You can compress Linux files with the open-source compression tool Gzip or with Zip or tar , which is recognized by most operating systems. if you need create backup linux this tutorial may help you, this is basic tutorial compress and create archiving your file.

By convention, compressed files are given the extension .gz. The command Gzip creates a compressed file ending with .gz; Gunzip extracts the compressed files and removes the .gz file.

To compress a file, at a shell prompt, type the following this sample command :

The file will be compressed and saved as filename.ext.gz.

To expand a compressed file, type:

The filename.ext.gz is deleted and replaced with filename.ext

now try another using zip, if you dont have this you can try install zip first, with yum :

yum install zip unzip -y

lets try tutorial using zip / unzip via centos :

If you exchange files with non-Linux users, you may want to use zip to avoid compatibility problems. Red Hat Linux can easily open zip or gzip files, but non-Linux operating systems may have problems with gzip files.

To compress a file with zip, type the following:

In this example, filename represents the file you are creating and files represents the files you want to put in the new file:

To extract the contents of a zip file, type:

You can zip or gzip multiple files at the same time. List the files with a space between each one.

The above command will compress file1, file2, file3, and the contents of the /user/work/school directory and put them in filename.gz.


Now after see command how to using zip and gzip, you can see how to using tar.
Archiving with Tar
Tar files place several files or the contents of a directory or directories in one file. This is a good way to create backups and archives. Usually, tar files end with the .tar extension.

To create a tar file, type:

In this example, createfilename.tar represents the file you are creating and files/directories represents the files or directories you want to put in the new file.

The following input would create a tar file using absolute pathnames:

The above command would place all the files in the /domain1 subdirectory and the /domain2 subdirectory in a new file called mynewtarfile.tar in the current working directory.

The Linux centos command tar -cvf foo.tar file1.txt file2.txt file3.txt would place file1.txt, file2.txt and file3.txt in a new file called foo.tar.

To list the contents of a tar file, type:

contents of a tar file, type:

This command does not remove the .tar file, but it places copies of the .tar contents in the current working directory.

The tar command does not compress files automatically. You can compress tar files with:

Compressed tar files are conventionally given the extension .tgz and are compressed with gzip.
To expand a compressed tar file type:

thats it, maybe you can see another command or try another command using tar with linux centos

Leave a Reply

Your email address will not be published. Required fields are marked *