Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

Delete Files > 1 Month Old, How id it Done?

I need a script to run weekly which will delete files in the /ckpjnl directory and its subdirectories that
1) are more than 1 month old and
2) do not have an extension of '.cnf'
Were are using crontab for other jobs now.
Thanks.
0
snydero
Asked:
snydero
  • 2
1 Solution
 
HalldorGCommented:
for i in $(find /ckpjnl +ctime 30 | grep -v ".cnf$")
do
   rm -f $i
done
0
 
HalldorGCommented:
for i in $(find /ckpjnl -ctime +30 | grep -v ".cnf$")
do
   rm -f $i
done
0
 
snyderoAuthor Commented:
I had to use the mtime parm, not ctime to make it work sensibly.
Thanks for the expertise.
0
 
JSchneiderCommented:
I tried this example on FreeBSD. The problem I have is that if any of the file names have a space in them, they are parsed out seperately and then the $i parameter does not carry the entire filename. Is there a simple way to solve this?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now