Solved

Removing a file from a tarball

Posted on 2011-03-08
7
537 Views
Last Modified: 2013-12-06
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

0
Comment
Question by:gram77
7 Comments
 

Author Comment

by:gram77
ID: 35080217
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
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 100 total points
ID: 35080276
see if your tar supports the --delete option

http://unixhelp.ed.ac.uk/CGI/man-cgi?tar
0
 
LVL 10

Expert Comment

by:Martin_J_Parker
ID: 35081383
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 31

Accepted Solution

by:
farzanj earned 400 total points
ID: 35082277
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
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 400 total points
ID: 35082294
Few months back, I had asked the exact same question:
Take a look.
http://www.experts-exchange.com/OS/Linux/Q_26576459.html
0
 
LVL 10

Expert Comment

by:Martin_J_Parker
ID: 35082391
Oh yes, I forgot that you would have to uncompress first.
faranj, shouldn't that be "gunzip" rather than "unzip"?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35082469
Yes, use gunzip.  Sorry about that.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question