LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-25-2013, 10:01 PM   #1
Kalibo
LQ Newbie
 
Registered: Dec 2013
Posts: 6

Rep: Reputation: Disabled
How to overwrite existing files by using tar command (Remove extra files)


Hello,

I want to overwrite files by using tar command.

But I also want to remove extra files.

for example:
Original files.
a/1,2
TAR files
a/1'

After extraction
a/1' (Because there is no "2" file in tar file.

My question is how to delete file "2" by using tar.
 
Old 12-25-2013, 10:39 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
since you are overwriting files, and want to delete files that aren't in the tar file - the EASIEST way is to just delete everything first.
 
Old 12-25-2013, 10:42 PM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,363

Rep: Reputation: 135Reputation: 135
Hi Kalibo, Welcome to LQ.

try this.

Code:
tar --delete -f a.tar a/2
 
Old 12-25-2013, 11:26 PM   #4
Kalibo
LQ Newbie
 
Registered: Dec 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Is there no other way to delete files that aren't in the tar file after extraction?

There is too risky to delete everything before extraction behavior...

Quote:
Originally Posted by jpollard View Post
since you are overwriting files, and want to delete files that aren't in the tar file - the EASIEST way is to just delete everything first.
 
Old 12-25-2013, 11:27 PM   #5
Kalibo
LQ Newbie
 
Registered: Dec 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thank you for reply.

But actually, I want to delete files that aren't in the tar file.
This command is proposed to delete file which is in the tar.

Quote:
Originally Posted by divyashree View Post
Hi Kalibo, Welcome to LQ.

try this.

Code:
tar --delete -f a.tar a/2
 
Old 12-25-2013, 11:32 PM   #6
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,363

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by Kalibo View Post
Thank you for reply.

But actually, I want to delete files that aren't in the tar file.
This command is proposed to delete file which is in the tar.
How can you delete a file that doesn't exist. confused ?? You want to delete file from tar or from the source dir ?
 
Old 12-26-2013, 12:27 AM   #7
Kalibo
LQ Newbie
 
Registered: Dec 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Sorry for unclear statement.

For example. I have two files under directory A.

A/aaa.txt
A/bbb.txt

1. tar directory A without aaa.txt to backup.tar
=> backup.tar *(without aaa.txt)*

2. Untar backup.tar to directory A
A/aaa.txt -> Not in backup.tar
A/bbb.txt -> Update from backup.tar

I want to remove aaa.txt because there is no aaa.txt file in backup.tar

Quote:
Originally Posted by divyashree View Post
How can you delete a file that doesn't exist. confused ?? You want to delete file from tar or from the source dir ?

Last edited by Kalibo; 12-26-2013 at 12:30 AM.
 
Old 12-26-2013, 12:37 AM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
Quote:
Originally Posted by Kalibo View Post
Is there no other way to delete files that aren't in the tar file after extraction?

There is too risky to delete everything before extraction behavior...
Don't like that? rename the directory, then let tar recreate the directory + contents, then delete the renamed directory.

Same result.
 
Old 12-26-2013, 12:41 AM   #9
Kalibo
LQ Newbie
 
Registered: Dec 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
jpollard,

Thank you for reply.

Because I dont have enough disk size to allocate two directories...

Quote:
Originally Posted by jpollard View Post
Don't like that? rename the directory, then let tar recreate the directory + contents, then delete the renamed directory.

Same result.
 
Old 12-26-2013, 12:42 AM   #10
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,363

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by Kalibo View Post
Sorry for unclear statement.

For example. I have two files under directory A.

A/aaa.txt
A/bbb.txt

1. tar directory A without aaa.txt to backup.tar
=> backup.tar *(without aaa.txt)*

2. Untar backup.tar to directory A
A/aaa.txt -> Not in backup.tar
A/bbb.txt -> Update from backup.tar

I want to remove aaa.txt because there is no aaa.txt file in backup.tar

The option -u is there for tar. Its used to update the tar archive with new file. And then delete/dont include the aaa.txt.
Try this:

PHP Code:
tar -uf A.tar A/bbb.txt 
Then
PHP Code:
tar --delete -f A.tar A/aaa.txt 

Last edited by divyashree; 12-26-2013 at 12:53 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tar file without remove existing data ust Linux - Newbie 3 06-10-2009 01:55 AM
cp command: how can I make it not automatically overwrite files? hamish Linux - Software 6 11-18-2006 11:30 AM
How do I move files without overwrite exitng files? nadavvin Linux - General 10 11-03-2006 02:49 PM
How to remove those files after tar Eileen Linux - Software 3 05-04-2006 02:17 AM
how to remove installed tar files marvc Linux - Software 3 04-17-2003 07:35 PM


All times are GMT -5. The time now is 01:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration