This is a series of lessons of “Basic Commands “ that focuses on command-line usage, in this serie you will learn the tools and tricks of the command line, which are in many cases faster, more powerfull, and more flexible than GUIprogram.
Today in this part will show you the main commands to compress/decompress files using rar, bzip, tarball(tar) and gunzip.
Tarball (tar):
GNU tar is an archiver that creates and handles file archives in various formats using the ‘tar’ command ,it was originally used as a backup tool to write data to magnetic tape drives .You can use tar to create file archives, to extract files from previously created archives, store additional files, or update or list files which were already stored.
-Create a uncompressed tarball :
tar -cvf archive.tar file1
-Create an archive containing ‘file1′, ‘file2′ and ‘dir1:
tar -cvf archive.tar file1 file2 dir1
-Show contents of an archive:
tar -tf archive.tar
-Extract a tarball :
tar -xvf archive.tar
-Extract a tarball into / tmp :
tar -xvf archive.tar -C /tmp
-Create a tarball compressed into bzip2
tar -cvfj archive.tar.bz2 dir1
-Decompress a compressed tar archive in bzip2
tar -xvfj archive.tar.bz2
-Decompress a compressed tar archive in gzip
tar -cvfz archive.tar.gz dir1
-Decompress a compressed tar archive in gzip
tar -xvfz archive.tar.gz
Meanning of the c,v,f and z,j options:
-’c’ option tells tar to create an archive,
-’v’ displays the files added to the tarball and
-’f’ specifies the filename. After the filename, all other parameters are the files or directories to add to the archive.
Tarballs are commonly compressed using gzip or bzip2 using the -z or -j command options.
For complete details, see the tar man page
$ man tar
bzip2 :
bzip2 is a freely available, patent free (see below), high-quality data compressor. It typically compresses files to within 10% to 15% of the best available techniques (the PPM family of statistical compressors), whilst being around twice as fast at compression and six times faster at decompression.(Read the documentation of bzip2).
-Compress a file called ‘file1′
bzip2 file1
-Compress a file called ‘file1′
bzip2 file1
-Decompress a file called ‘file1.bz2′
bunzip2 file1.bz2
RAR Archiver :
RAR is a proprietary file format for data compression and archiving, developed by Eugene Roshal.
Under Linux and UNIX, use command called unrar. By default unrar is not being installed on Linux, FreeBSD or UNIX oses. You can install unrar command with the help of apt-get or yum command.
-Create an archive rar called ‘file1.rar’
rar a file1.rar test_file
-Compress ‘file1′, ‘file2′ and ‘dir1′ simultaneously
rar a file1.rar file1 file2 dir1
-Decompress rar archive
rar x file1.rar
OR
unrar x file1.rar
Gzip :
gzip is a software application used for file compression. gzip is short for GNU zip; the program is a free software replacement for the compress program used in early Unix systems, intended for use by the GNU Project.
gzip was created by Jean-Loup Gailly and Mark Adler. Version 0.1 was first publicly released on October 31, 1992. Version 1.0 followed in February 1993.
Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times.There is a good article if you want to learn more a bout gzip, see this link.
-Decompress a file called ‘file1.gz’
gunzip file1.gz
-Compress a file called ‘file1′
gzip file1
-Compress with maximum compression
gzip -9 file1
ZIP Archiver:
zip is a compression and file packaging utility for Unix, VMS, MSDOS, OS/2, Windows NT, Minix, Atari and Macintosh, Amiga and Acorn RISC OS. It is analogous to a combination of the UNIX commands tarand compress.
-Create an archive compressed in zip
zip file1.zip file1
-Compress in zip several files and directories simultaneously
zip -r file1.zip file1 file2 dir1
-Decompress a file called file1
unzip file1
This was all for this part, see you in Part II of the Basic commands series.
Originally posted 2016-01-11 05:52:59.