How do you move (mv) files to a backup directory from a particular directory when the files are
older the 24hrs copied from a batch script run every 24 hrs.
Would you use find or some kind of timestamp.timestamp="$(date +'%m%d%I%M')"
try find maybe like this: -mtime +1 means older than one day (24 hours)
find /particular/directory -mtime +1 | \
while read file
do
b=`basename "$file"`
mv $file /path/to/new/directory/"$b"
done
Jim, I believe there is some confusion regarding the mtime parameter. +0 stands for older than one day, +1 would stand for older than 2 days. Check this out:
# date
Tue Apr 4 04:28:16 IST 2006
# ls -ltr
:
:
-rw-r--r-- 1 root sys 0 Apr 3 04:20 testfile
-rw-r--r-- 1 root sys 1300 Apr 3 23:58 fs.c
-rw-r--r-- 1 root sys 583 Apr 4 04:08 freesp.c
-rw-r--r-- 1 root sys 971 Apr 4 04:11 daemon.c
-rwxr-xr-x 1 root sys 28672 Apr 4 04:11 a.out
-rwxr-xr-x 1 root sys 24576 Apr 4 04:11 daemon
-rw-r--r-- 1 root sys 139 Mar 22 12:56 ./t1.c
-rwxr-xr-x 1 root sys 38 Mar 31 08:05 ./shell/test.sh
drwxr-xr-x 2 root sys 8192 Mar 31 08:05 ./shell
-rw-r--r-- 1 root sys 0 Apr 3 04:20 ./testfile
# find . -mtime +0 |xargs ls -ldtr|more
:
-rw-r--r-- 1 root sys 139 Mar 22 12:56 ./t1.c
-rwxr-xr-x 1 root sys 38 Mar 31 08:05 ./shell/test.sh
drwxr-xr-x 2 root sys 8192 Mar 31 08:05 ./shell
-rw-r--r-- 1 root sys 0 Apr 3 04:20 ./testfile
# find . -mtime +1 |xargs ls -ldtr|more
:
-rw-r--r-- 1 root sys 139 Mar 22 12:56 ./t1.c
-rwxr-xr-x 1 root sys 38 Mar 31 08:05 ./shell/test.sh
drwxr-xr-x 2 root sys 8192 Mar 31 08:05 ./shell
Note that the file testfile shows up on using +0 and not on using +1. Check Perderabo's last post in this thread.