Move old files script


Subject: Move old files script
From: Mike Barsalou (mbarsalou@aidea.org)
Date: Mon Apr 01 2002 - 13:56:47 AKST


Since so many of you have been laboring through this process with me, I
thought I would share the resulting bash script that will move old files
from one directory to another meeting certain criteria.

I was trying to figure out how to replace the +2190 parameter in the find
command below with a variable but was unsuccessful...

You could also make this script accept command line arguments.

Please let me know if there is an easier way....I tried to comment it as
best as possible.

---cut here---

#!/bin/sh

# Copyright Mike Barsalou @ 2002
# This script will copy (or optionally move) all files after a certain
# number of days old.

# Set the max number of bytes of data that you want moved
# default maxbytes=650000000 for CD size
maxbytes=650000000

# count is running total bytes of files
count=0

#dest is destination of files being copied/moved
dest='/cdburn/'

# 2920 = 8 years
# 2555 = 7 years
# 2190 = 6 years
# 1825 = 5 years

# find all files that are in the current directory (and subdirs) and are
older than 6 years (+2190)
for foo in `find ./ -mtime +2190`
     do

# The following line is equivalent to count=count +(sizeoffile)
        let "count += `du -b $foo | awk '{print $1}' `"

# If the count hasn't exceeded our limit for the dest dir then let's copy it
        if [ "$count" -lt "$maxbytes" ]
          then

# we need to make sure that we keep the current attributes and
# directory structure.
           cp --preserve --parents $foo $dest

# Uncomment the next line to optionally remove the file
# rm -f $foo

# spit out the name and the current byte count
           echo $foo, $count
        fi
     done



This archive was generated by hypermail 2a23 : Mon Apr 01 2002 - 13:58:43 AKST