Files Compression and Archive
This one also came from the series of articles that i wrote to CyberRealm page of Sunday Observer. I must admit that some things are obsolete, but you can learn about commands.
Before going to Linux, first let’s look at the difference between compressed file and archived file. An archived file is a collection of file and directory gathered into one file. The file is not compresses and generally it’s slightly larger then the total size of the files inside. Compressed file is a file with less size. You generally call these zip files. They can be a single file or an archive.
In new versions on RedHat Linux, there is a package called “File Roller”. It’s a GUI tool that you can work with archive and compressed files, easily. In Red Hat Linux 9 go to Main menu => Accessories => File Roller (depending on the version also the path may change for example in Enterprise Linux 4 this is located in System Tools sub-menu).
You can open a terminal and type file-roller in it and load the tool. It’s much like Winzip in Windows. Using it is a piece of cake. So let’s move to the shell.
File Archive
There are so many archive tools in various distributions. The most common is the Tape Archive, know as “tar”. You get most on the sources of the packages in tar archives and compressed using some other tool.
Create an archive: the command is tar -cvf filename.tar directory_or_file_name. Here you have to specify the file name of the archive file after the options, and then the directory or the file you want to archive. When specifying the archive name it’s important to have the “.tar” extension, so you can identify that file is an archive. The options give instructions as follows
-c Create an archive file
-f Follow the file name specified
-v Verbose, the progress of the file being archived
If you want you can “tar” multiple files. Use the same command and specify the files names with a space. For example let’s say you want archive files in “/home/user1/assignments” and “/home/user1/homework” and make an archive called “mywork.tar” The command goes like this.
tar –cvf mywork.tar /home/user1/assignments /home/user1/homework
List contents: tar -tvf filename.tar
-t is the list option and –v and –f are same as above.
Extract files: tar -xvf filename.tar
-x is the extract option and –v and –f are same as above.
Dealing with compressed archives: As I mentioned earlier most of the tar file in the internet are compressed. But by default tar won’t compress the archives. So you must use a compression tools to so the zipping. You should first use the tar command and make your archive and then compress it using a compression tool. But tar is capable of interacting with certain compression tools and gets the work done for you.
Tar can work with “gzip” and “bzip”. (We’ll discuss about zipping in detailed later). A gzipped tar has tar.gz or .tgz extension. And bzipped tar has .tar.b2z or tbz extensions.
Gzipped tar files: The same command with a –z options is used. So the commands are
tar -czvf filename.tar.gz directory_or_file_name is to create a gzipped tar file.
tar -xzvf filename.tar.gz command do both unzipping and “untaring”.
Bzipped tar files: This time the option is –j. so the commands are
tar -cjvf filename.tar.b2z directory_or_file_name command create a tar.b2z file.
tar -xjvf filename.tar.b2z unzip and untar the flie.
pax (portable archive exchange) Archiving Tool
In today’s world there are a large number of Linux operating systems and they have come up with a lot of similar but incompatible archives. Even the tools with same name use different storage formats on different systems. To overcome this problem the pax is introduced. Pax can read and write a wide variety of archive formats.
pax -fv filename.extention :list the contents
pax -rv -f filename.extention :extract files from the archive
pax -wv -f filename.extention source_directory :create an archive
-f and –v options are the same as in tar and –r is read and –w is write.
Dharshin De Silva
Delicious
Digg
Reddit
Magnoliacom
Newsvine
Furl
Google
Yahoo
Technorati
Icerocket



Post new comment