1748022 Members
5377 Online
108757 Solutions
New Discussion юеВ

Re: script to move files

 
SOLVED
Go to solution
Peter Nikitka
Honored Contributor

Re: script to move files

Hi,

the easiest thing would be to keep the monthly archive outside the find tree:

...
M_ARCHIVE=${DIR}-bymonth

[ -d $M_ARCHIVE ] || mkdir $M_ARCHIVE

for a in `find $DIR -ctime 1 -type f`
do
...
[ -d $M_ARCHIVE/$month ] || mkdir $M_ARCHIVE/$month
mv $file $M_ARCHIVE/$month
...
done

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
James R. Ferguson
Acclaimed Contributor

Re: script to move files

Hi (again) Lawrenzo:

You are using the 'ctime' or last change time for a file's inode. The 'ctime' changes whenever ownership, permissions are changed or whenever a file is renamed.

Using 'ctime' tracks metadata changes. If you truly want to find files based on *modification* of their data, you need to use 'mtime'.

The manpages for 'stat(2)' will clarify things for you.

BTW, I still suggest the 'cpio' method I posted above for your archiving needs.

Regards!

...JRF...
Sandman!
Honored Contributor

Re: script to move files

Modify the find command to exclude the other dir as follows:

find $DIR ! -path "/usr/dump/JDE/data/out/ARCHIVE/day.mnth/*" -ctime 1 -type f

~hope it helps
lawrenzo_1
Super Advisor

Re: script to move files

Thank you everyone - got there in the end!

James thanks for the suggestion however the business have request the archive directories this was.

I like your idea however it wouldn't work for what is required as there are over 3000 files daily that sometimes require a search etc etc.


Chris.
hello