LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 10-13-2008, 03:13 AM   #1
timnewton
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Rep: Reputation: 0
script for removing 30day old files but keeping *.zip


Hi there,

i have just signed up because i have started a new job and we now use red hat servers which i dont have much linux experience.

here is my problem :-

we have a set of folders which are used by a few companies for Ftp. we want to delete everything which is 30 days old or older (i have found that code) but there are 3 .zip files in each folder which will always be older than 30days that we want to keep.

here is the code i have be hacking around

find /Raid/ftp -type f rm -r -mtime +30 -exec rm '{}' \;

so what is the best way to do this? the only thing i can think of is to remove all 30day files and then copy the zip files back everytime. but i feel it is a messy solution.

Any input would be greatly appreciated.

Many thanks in advance

Regards

Tim Newton
 
Old 10-13-2008, 03:22 AM   #2
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 38
How about piping the results of the find command, removing all entries with .zip in the file, and then deleting the remaining files mentioned in the temp file? You could add the whole thing into a shell script and run that instead.
Something like this:
Code:
#!/bin/bash
find /Raid/ftp -type f -mtime +30 -print > /tmp/tempfile   #tempfile has a list of all files older than 30 days
sed -i 's/zip/d' /tmp/tempfile    #all zip files are removed from tempfile now
rm `cat /tmp/tempfile`          #the remaining files are deleted
You might want to test that code a couple times before you run it.

Last edited by indeliblestamp; 10-13-2008 at 03:23 AM. Reason: formatting changes
 
Old 10-13-2008, 03:34 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

find can do this all at once. Example:

find /Raid/ftp -type f \! -iname "*zip" -mtime +30

The blue part tells find not (\!, -not can also be used) to include zip (any case, end of the string) files.

Hope this helps.

PS: Here are some find related links:

examples of using UNIX find
real world FIND usage
 
Old 10-13-2008, 03:40 AM   #4
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 38
Hey, that's an awesome tip!
 
Old 10-13-2008, 04:06 AM   #5
timnewton
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
wow thanks for the quick response

i have tried find /Raid/ftp -type f \! -iname "*zip" -mtime +30

but it's not deleting the files do i to use a -r somewhere?

but thanks so much for the help, i have to admit i really like how the linux server works i might be a full convert soon
 
Old 10-13-2008, 06:02 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Quote:
Originally Posted by timnewton View Post
wow thanks for the quick response

i have tried find /Raid/ftp -type f \! -iname "*zip" -mtime +30

but it's not deleting the files do i to use a -r somewhere?
That's because I did not include the -exec rm -f {} \; part, it's always a good idea to see what your find statement comes up with before you start deleting stuff (especially when you are new at this).

Add the 'missing' part to the end of my original statement (after checking you are getting the wanted results).
 
Old 10-13-2008, 10:36 AM   #7
gg-jgs
LQ Newbie
 
Registered: Feb 2006
Posts: 2

Rep: Reputation: 0
good!!!!!!!!!!!!!!!
 
Old 10-14-2008, 03:50 AM   #8
timnewton
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
WOW thanks so much,

Sorry i was late to reply i just got swamped with work,

Thanks very much for your help all of you
 
  


Reply

Tags
files, old, removing


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to rename files removing one character Byenary Linux - Newbie 2 04-08-2008 10:12 AM
Script to Add files to a Zip archive with out unzipping it !! prashix Programming 12 10-23-2007 09:19 AM
Installing openSuSE removing fedora and keeping xp netjack Suse/Novell 3 04-30-2006 12:40 AM
Install on laptop keeping xp and removing fedora netjack Ubuntu 11 04-13-2006 11:04 AM
removing RH9 but keeping my ntfs partition bof Red Hat 6 12-25-2004 09:14 PM


All times are GMT -5. The time now is 05:00 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration