script for removing 30day old files but keeping *.zip
Red HatThis forum is for the discussion of Red Hat Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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.
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 arungoodboy; 10-13-2008 at 03:23 AM.
Reason: formatting changes
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.