DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.
Using the “tar” and “gzip” commands
In UNIX files are packed using the Unix Tape ARchive utility (derived from tape archive and commonly referred to as “tarball”), otherwise are compressed and stored using the GNU zip utilities.
The purpose of this post in not do a detailed and exhaustive description about “tar” and “gzip” commands, but present the essential to use it of an easy way. I hope you enjoy the post!
Basically the “tar”(Tape ARchive) command allows pack/unpack, and the gzip(GNU zip) command compress/uncompress files.
tar
The “tar” command allows us group and ungroup( pack and unpack), a set of files and/or folders into a single file.To pack some folders and files listed above into a single file, we can run the “tar” command with the following parameters.
| tar -cvf application. tar * |
| tar –cvf application. tar java PERL requirements.txt config.xml |
| tar cvf application. tar java PERL requirements.txt config.xml |
Regardless of how the parameters can be referred, below is listed a description of the used parameters:
Option | Meaning | Description |
-c | Create | Create a new archive |
-v | Verbose | Verbosely list files which are processed |
-f | File=ARCHIVE | Use archive file or device |
Otherwise the “tar” command can be used to the reverse process: unpack or extract a set of files, directly from the “tar” file:
Option | Meaning | Description |
-x | eXtract | Extract files from an archive |
gzip
This command simply allow to compress a file: any type of file(with the “tar” extension or any other).To compress a file we can use the following syntax:
| gunzip myfile. tar .gz |
The “tar” also allows compress the “tar” result file, by the “z” option as shown below:
| tar cvzf archive_name. tar .gz dirname |
tar and gzip
Oftentimes can be confused to understand the meaning of “tar” and “gzip” commands, because they are used together at the same command line through the pipe operator “|”. Example 1
| tar cvf * | gzip > oracle. tar .gz |
The first command(before the pipe) is the “tar”, which pack all files in the current directory.
After this, the ”tar” file is compress :”gzip”(after the pipe) and produce the final file(by the redirection operator “>”) : “oracle.tar.gz”.
Example 2
| gunzip < oracle. tar .gz | tar xvf - |
In this example the “oracle.tar.gz” file is unzip and the result is a “tar” file that is placed in the “tar” command to unpack. With the hyphen the data resulting from the “gunzip” command is used as input in the tar command.
Useful list
Below you can see a list of very useful actions included these commands:
- List the contents of “tar” file
| tar tvf archive_name. tar |
- Extract a single file from “tar” file
| tar xvf oracle. tar java/MyLib.java |
- Add a file to an existing ”tar” file
| tar rvf oracle. tar conf.cnf |
- Untar an archive to a different directory
| tar -zxf oracle. tar .gz -C ora |
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.