Removing a file from a tarball

I have a tar mytar.tar.gz which is a zipped version of the tar.

I check for existance of file abc.properties and def.properties which i find in the tar.

Q)  I need to delete these files abc.properties and def.properties from the tar.
Is there a single command that i can use to do this? without untar, delete and retar the file?


tar -ztvf mytar.tar.gz | grep abc.properties
-rwxr-xr-x avi /cdv      581 2011-03-01 10:20:37 ./runconfig/run/attri/abc.properties <--delete this file
-rwxr-xr-x avi /cdv      131 2009-09-30 15:00:03 ./runconfig/run/param/abc.properties <--delete this file

tar -ztvf mytar.tar.gz | grep def.properties
-rwxr-xr-x avi /cdv      581 2011-03-01 10:20:37 ./runconfig/run/attri/def.properties <--delete this file
-rwxr-xr-x avi /cdv      131 2009-09-30 15:00:03 ./runconfig/run/param/def.properties <--delete this file

gram77Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
farzanjConnect With a Mentor Commented:
Yes, you can delete from tar.  The bad news is that you still need to unzip it and then re-zip it.

So you have to do the following
 
unzip mytar.tgz
tar -f mytar.tar --delete './runconfig/run/*/abc.properties'
tar -f mytar.tar --delete './runconfig/run/*/def.properties'
gzip mytar.tar

Open in new window

0
 
gram77Author Commented:
I am using the follwoing Linux:
uname -a
Linux abc232 2.6.9-89.0.9.EL #1 Wed Aug 19 08:01:18 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant Update 6)
0
 
omarfaridConnect With a Mentor Commented:
see if your tar supports the --delete option

http://unixhelp.ed.ac.uk/CGI/man-cgi?tar
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Martin_J_ParkerCommented:
Redhat Enterprise does support --delete for files but not for mag tapes.  
Is it a tar file on a disk or on a tape?
0
 
farzanjConnect With a Mentor Commented:
Few months back, I had asked the exact same question:
Take a look.
http://www.experts-exchange.com/OS/Linux/Q_26576459.html
0
 
Martin_J_ParkerCommented:
Oh yes, I forgot that you would have to uncompress first.
faranj, shouldn't that be "gunzip" rather than "unzip"?
0
 
farzanjCommented:
Yes, use gunzip.  Sorry about that.
0
All Courses

From novice to tech pro — start learning today.