Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo
- - - - -

Using File Archiver and Compression Programs in Linux


  • Please log in to reply
4 replies to this topic

#1 Nicholas_Kang

Nicholas_Kang

  • Malware Study Hall Junior
  • 348 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Penang
  • Local time:06:27 PM

Posted 12 September 2018 - 07:04 AM

Using File Archivers and Compression Programs in Linux



Guide Overview

The purpose of this guide is to teach you how to use the various file archivers and compression programs in Linux.

Tools Needed
  • A working Linux PC (Any Linux distro)
  • tar 
  • gzip
  • zip
Instructions

tar: The tape archival

It is often desirable to combine groups of files into a single file called an archive when sending them to someone by emails, FTP or code repositories. The tar (tape archiver) command is an archiver which can be used for archiving files.

We will now consider several key options of tar. Only one option can be used at a time.

-c Creates an archive
-x Extracts files from an archive
-t Displays files in an archive (table of contents)

The above 3 options are often used together with the following 2 options:

-f Specifies the name of the archive (filename)
-v Displays the progress (verbose)

This is how we create an archive from 2 uncompressed files:

You type:

$ tar -cvf examplearchive.tar foo bar
The shell returns:
 
a foo 364k 
a bar 3785k
The 2 example files above are foo and bar. Note that the verbose output lines all begin with an "a" (meaning: append).

By convention, the .tar extension is used so that one will remember to use the same tar command to extract files from the archive. The files won't be deleted after they are combined to form an archive. To delete them, use the --remove-files option.
 
$ tar -cvf --remove-files examplearchive.tar foo bar
 
 
 
Now, to extract files from an archive, we use the -x option:
 
$ tar -xvf examplearchive.tar
Shell output:
 
x foo, 372267 bytes, 728 tape blocks
x bar, 3875302 bytes, 7569 tape blocks
Note that x indicates extract and the archive won't be deleted after the extraction is complete.


 

Perhaps you want to know the content of the files in an archive before deciding what you want to do to them. You may use the -t option:
 
$ tar -tvf examplearchive.tar
Shell output (listing):
 
-rw-r--r-- 102/10 372267 Jan 10 10:05 2018 foo
-rw-r--r-- 102/10 3875302 Jan 10 10:01 2018 bar
A short video on tar's usage:
 


We have just scratched the surface of tar, feel free to visit the following links to learn more about tar:

GNU tar manual
tar Linux man page

Reference:

Das, S. (2013). Your UNIX/Linux: The ultimate guide. New York: McGraw-Hill.

"When the product is free the real product is YOU."
 

An offer of free anti-virus or anti-malware software is essentially a marketing techniqueBottom line...it's all about generating revenue and finding new and creative ways to do so. As such, users may have to deal with occasional nagging pop-ups, nuisance advertising and prompts to upgrade to the paid version or purchase other products.

By using such free programs, you are essentially agreeing to the terms of the vendor's service which includes those annoying pop-ups and ads.
 
Read more here...


BC AdBot (Login to Remove)

 


#2 Nicholas_Kang

Nicholas_Kang
  • Topic Starter

  • Malware Study Hall Junior
  • 348 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Penang
  • Local time:06:27 PM

Posted 13 September 2018 - 06:35 AM

Instructions

gzip: The Compression Program

Any PC user will likely encounter compressed files at some point while using his/her PC. For instance, you may want to compress a file before sending it as an email attachment.

We will use gzip to handle file compression in Linux. gzip provides the extension .gz to the compressed filename and removes the original file.

To compress a file, we simply make the filename the argument to the command:
 



gzip foo
In the above example, foo is the file to be compressed. gzip will then create the zipped file with the name foo.gz and removes the original file.


 


To see the amount of compression achieved, use the -l (list) option together with the compressed filename as the argument:
 
$ gzip -l foo.gz
This will also work.
 
$ gzip -l foo
The extension .gz is not required in this case (when used with the -l option).

Shell output (listing):
 
compressed  uncompr.  ratio  uncompressed_name
  788096    3875302   79.6%        foo
 


To uncompress a zipped file, one can:
  • use the gzip command with the -d option
  • use the gunzip command
gunzip foo.gz
or
gzip -d foo.gz
Once decompressed, you obtain the original file and the compressed file no longer exists.


 


The tar command has been mentioned above. Perhaps you may think we can combine tar and gzip to reduce the size of the archive created by tar.

Well, you guessed it!

To zip an archive, we simply treat the archive as an ordinary file to be compressed:
 
gzip foo.tar
This will create a file with the name foo.tar.gz and removes foo.tar. Take note that there ia another shorthand notation often seen which is .tgz.

Now, to extract .tgz files, you reverse the process above; first decompress with gzip -d or gunzip, then extract archive using tar.
 
gunzip foo.tar.gz
tar -xvf foo.tar
gzip and tar are so often used that GNU tar has a -z option which compresses and archives together (and decompresses and extracts together):
 
tar -cvzf foobar.tar.gz foo bar
The above line creates a zipped archive with the filename foobar.tar.gz from the 2 files foo and bar.
 
tar -xvzf foobar.tar.gz
The above line decompresses and extracts the zipped archive foobar.tar.gz and produces 2 files foo and bar (assuming that it is the same foobar.tar.gz which we created in the previous line).

2 videos on using gzip in Linux:
 



For more info about gzip, kindly visit the links below:

GNU gzip documentation
gzip home page

Reference:

Das, S. (2013). Your UNIX/Linux: The ultimate guide.New York: McGraw-Hill.

Edited by Al1000, 14 September 2018 - 06:10 PM.
remove unwanted text by author's request

"When the product is free the real product is YOU."
 

An offer of free anti-virus or anti-malware software is essentially a marketing techniqueBottom line...it's all about generating revenue and finding new and creative ways to do so. As such, users may have to deal with occasional nagging pop-ups, nuisance advertising and prompts to upgrade to the paid version or purchase other products.

By using such free programs, you are essentially agreeing to the terms of the vendor's service which includes those annoying pop-ups and ads.
 
Read more here...


#3 Nicholas_Kang

Nicholas_Kang
  • Topic Starter

  • Malware Study Hall Junior
  • 348 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Penang
  • Local time:06:27 PM

Posted 14 September 2018 - 05:52 AM

Instructions

zip: The compression and archival program

Everyone who uses a PC will certainly be familiar with the .zip file extension when compressing files. The .zip file format was developed in 1989 and released to the public domain in the same year by Phil Katz.

The .zip file format was meant to be a replacement of the old ARC compression format and was first implemented on PKZIP, the file compression utility developed by PKWARE, founded by Katz himself. The file format quickly became popular among PC users (which is why so many PC users are familiar with it!) and was supported by major OSes such as Microsoft Windows (1998) and Mac OS X (2003).

The .ZIP format proved so popular that it became the de facto standard for data compression and remains in use throughout the world after more than 30 years. [1]



The .zip format was first introduced to the UNIX family by the Info-ZIP project as the unzip command in 1989, followed by the zip command in 1992. We will be dealing with these 2 commands in this tutorial.


 


zip combines the compressing function of gzip with the archival function of tar. Instead of using tar with the -z option, you can use the zip command.

zip requires the first argument to be the compressed filename; the remaining arguments are interpreted as files and directories to be compressed.
 
$ zip foobar.zip foo bar
Shell output:
 
adding: foo (deflated 80%)
adding: bar (deflated 66%)
Note that the .zip extension need not exist in the zip file's filename. This means you can name your zipped file foobar instead of foobar.zip for the first argument in the above command.

zip is unusual in that it does not overwrite existing compressed file. If foobar.zip exists, files will be updated or appended to the archive depending on whether they already exists in the archive.


 


Just like cp, rm, chmod and other UNIX commands, recursive operations are supported in zip. The option to be used is -r:
 
$ zip -r Nicholas_user_files.zip /home/Nicholas
The above command zips all files in the /home/Nicholas directory which contain my user files.


 


To decompress a file, we use the unzip command. (History aside: Recall that unzip was available earlier than zip!)
 
$ unzip foobar.zip
Shell output:
 
Archive: foobar.zip
inflating: foo
inflating: bar
The above output assumes there is no file with the same filename as the uncompressed and extracted contents, i.e. foo and bar in the directory to which the files are unzipped to (the current directory in the above case).

If, however, a file with the same filename exists in the current directory, unzip will prompt the user to take appropriate actions:
 
replace foo? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
Note the last "y" is the user's input, which means he chooses to replace the file on disk with the extracted file originated from the zipped file. Enter "n" to retain the original file on disk, or choose to rename the file on disk with "r" to prevent overwriting. Use "A" with "y" or "n" to direct unzip to perform the decompression on the remaining files non-interactively. (Similar to Windows's "Yes to All" and "No to All" options.)


 


To view the archive, we use the -v option.
 
$ unzip -v foobar.zip
Shell output:
 
Archive: foobar.zip
 Length  Method   Size   Ratio    Date    Time    CRC-32   Name
 ------  ------   ----   -----    ----    ----    ------   ----
3875302  Defl:N  788068   80%   09-14-18  07:30  hew345fr  foo
 372267  Defl:N  128309   66%   09-14-18  07:29  errrg456  bar
 ------          ------   ---                              ------
4247569          916377   78%                              2 files
For more info about using zip, kindly refer to the UNIX zip man pages or watch the Youtube videos to learn more about zip:



Reference:

Das, S. (2013). Your UNIX/Linux: The ultimate guide. New York: McGraw-Hill.

Edited by Nicholas_Kang, 14 September 2018 - 05:53 AM.

"When the product is free the real product is YOU."
 

An offer of free anti-virus or anti-malware software is essentially a marketing techniqueBottom line...it's all about generating revenue and finding new and creative ways to do so. As such, users may have to deal with occasional nagging pop-ups, nuisance advertising and prompts to upgrade to the paid version or purchase other products.

By using such free programs, you are essentially agreeing to the terms of the vendor's service which includes those annoying pop-ups and ads.
 
Read more here...


#4 Chiragroop

Chiragroop

  • Members
  • 102 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:03:27 AM

Posted 21 September 2018 - 01:53 PM

Great post! :) This will help a lot of people.


Edited by Chiragroop, 21 September 2018 - 01:53 PM.


#5 Rocky Bennett

Rocky Bennett

  • Members
  • 2,955 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:New Mexico, USA
  • Local time:03:27 AM

Posted 22 September 2018 - 07:38 AM

Thanks. It is a lot for me to digest but I am working on it.


594965_zpsp5exvyzm.png





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users