Solved

Removing a file from a tarball

Posted on 2011-03-08
7
528 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now