Solved

Removing a file from a tarball

Posted on 2011-03-08
7
543 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Moving from Mcrypt to OpenSSL 18 72
PHP error function not working on AWS 10 163
expand ext4 on centos 6 5 68
Cron job never runs on vCenter 6.5 appliance 7 22
This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

731 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