File Compression and Archiving with Gzip, Zip, and Tar
Compressing with Gzip and Zip
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, which is recognized by most operating systems.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 command:
gzip filename.ext |
To expand a compressed file, type:
gunzip filename.ext.gz |
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:
zip -r filename.zip files |
To extract the contents of a zip file, type:
unzip filename.zip |
gzip filename.gz file1 file2 file3 /user/work/school |
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:
tar -cvf filename.tar files/directories |
You can use absolute or relative pathnames for these files and directories Separate the names of files and directories with a space.
The following input would create a tar file using absolute pathnames:
tar -cvf foo.tar /home/mine/work /home/mine/school |
The 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:
tar -tvf foo.tar |
tar -xvf foo.tar |
The tar command does not compress files automatically. You can compress tar files with:
tar -czvf foo.tar |
To expand a compressed tar file type:
tar -xzvf foo.tgz |
good
ReplyDeletehello
ReplyDelete