Thursday, September 27, 2012

How to extract the desired file/directory from a tar archive in Unix or Linux or Solaris


Question: To extract the desired file/directory from a tarball

Answer:  Pass the desired file/directory as an extra argument to the normal tar extraction command

Syntax:   tar –xvf  filename.tar  desiredfilename/dirname

Example: To extract a file which is under two directories

1.      First we need to know the location of the file in the tarball  ( tar –tvf filename.tar  | grep filename)
2.      Secondly we need to apply that location as an additional argument  ( tar –xvf filename.tar  “output of last command” )

Now the command part,

[vjsujay@cheetah:/home/vjsujay]#tar -tvf abcd.tar | grep FileD
tar: blocksize = 15
-rw-r--r-- 48153/63002     14 Aug  2 12:41 2012 ./c/d/FileD

[vjsujay@cheetah:/home/vjsujay]#tar -xvf abcd.tar ./c/d/FileD
tar: blocksize = 15
x ./c/d/FileD, 14 bytes, 1 tape blocks

NOTE: If similar file already exist in the same location, then please move the tarball to different location and extract it to avoid the overwritten of the file

1 comment:

oracle fusion hcm online Training said...

This list is without a doubt very useful.
Thank you for sharing the ones maximum critical weblog submission net internet web sites.
oracle cloud fusion financials