The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Deleting the files comparing the creation dates pssandeep UNIX for Dummies Questions & Answers 2 04-10-2008 07:54 AM
Archive script old files kayarsenal Shell Programming and Scripting 1 08-24-2006 10:46 PM
Archive files kayarsenal Shell Programming and Scripting 13 08-21-2006 08:01 AM
tar archive with .Z files Kun2112 UNIX for Dummies Questions & Answers 3 08-05-2005 06:42 AM
Deleting files automatically, the condition in the month of creation FabioALex UNIX for Dummies Questions & Answers 4 12-10-2001 05:14 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-12-2007
Registered User
 

Join Date: Nov 2006
Posts: 33
Lightbulb : D deleting files after the creation of a tar archive

Hi, I would modify to delete the files after creating the tar archive.
How I can modify the following command:

tar -cvvf logswitch.tar `find *.log* -mtime +5`

It create a tar with files that are older than 5 days.

Last edited by Minguccio75; 02-12-2007 at 07:24 AM. Reason: solution
Reply With Quote
Forum Sponsor
  #2  
Old 02-12-2007
tayyabq8's Avatar
Moderator
 

Join Date: Nov 2004
Location: Bahrain
Posts: 555
Try this:
Code:
tar -cvf logswitch.tar `find *.log* -mtime +5` && find *.log* -mtime +5 -exec rm {} \;
Reply With Quote
  #3  
Old 02-12-2007
Registered User
 

Join Date: Nov 2006
Posts: 33
Is there the possibility to erase the files using an option of the tar command?
Reply With Quote
  #4  
Old 02-12-2007
Registered User
 

Join Date: Nov 2006
Posts: 33
I found the solution:

tar -cvvf logswitch.tar `find *.log* -mtime $Days` --remove-files
Reply With Quote
  #5  
Old 02-12-2007
tayyabq8's Avatar
Moderator
 

Join Date: Nov 2004
Location: Bahrain
Posts: 555
Good, but It'll work with GNU tar only
Reply With Quote
  #6  
Old 02-13-2007
Registered User
 

Join Date: Feb 2007
Location: Israel
Posts: 24
for those without gnu tar

save file list in variable or file.
FILES=$(find ...)
or
find ... > /tmp/$(USER).flist.$$
then you can remove the files after the tar, without running find twice, (which might be a heavy process or) its state may change between the first and second iteration, causing you to actually lose data.

For example: if you run the command close to midnight. the first +5 will find files just older than 5 days and the second running after midnite will add files a day older. and even if you use it in the middle of the day, the timestamp of files can cause a miss the same way.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0