?
Solved

Removing a file from a tarball

Posted on 2011-03-08
7
Medium Priority
?
554 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 31

Accepted Solution

by:
farzanj earned 1600 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 1600 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Fine Tune your automatic Updates for Ubuntu / Debian
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 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