Artikel Terbaru

Sunday, 22 January 2012

Learn tar command with examples in linux or unix

Tar command in unix:-

Tar command is abbreviated as tape archive.tar is one of the most popular zipped/achive command in unix like zip in windows to compress the files and store all the files into single file tar.gz.

tar command examples in linux
tar and gzip are more popular zipped archive commands in linux or unix like zip,winrar etc in windows.I have also blogged about Top 10 gzip examples in linux,unix  for gzip usage.

Most of the open source frameworks like maven, tomcat,jboss etc..are shipped in tar.gz format to install in unix environments.blogging all these for reference.

Tar example usage :-

1.Creating archive tar.gz for a folder or tar the files:-

Tar –cvzf   newfilename.tar.gz existing-folder-name

This will compress create the tar version/zipped as new-file-name.tar.gz from the existing-folder.The structure of files ,directories,subdirectories in existing-folder are same way created for new-file-name.tar.gz

c- creating new gz file
z - compresse the filees
v- print the list of the files shown in stdout
f- with this option, archive name are specified with in command

2.Extract/unzip tar.gz file into a folder or untar
Tar –xvzf filename.tar.gz

X option means unzip the contents of this archive
Remaing options are same as like in #1

This will extract and copy all the files to the current directory with the folder as filename where this command is running.

3.Show all the files of tar file

tar  tvf  filename.tar.gz

This will show all the files in filename.tar.gz to stdout console.
Option t – list all the contents of the archive

Advantages with tar is it will take a backup of your files
Disadvantage is single file can not be extracted from the zipped or archived file

Extract or unzip archive with gunzip,tar command :-

With this both commands, we can used to unzip the tar.gz or .gz files.’

To unzip tar.gz file, there are two steps involved. First unzip .tar.gz into tar file in the following command and then use tar command

gunzip filename.tar.gz
tar –xzf filename.tar 

filename.tar is created with the first command, this is passed to tar command extract the files in the tar.

Hope you got basic start for tar,gunzip with examples.

Please feel free to comment and share your thoughts.