1833758 Members
2722 Online
110063 Solutions
New Discussion

Re: copy file

 
SOLVED
Go to solution
ust3
Regular Advisor

copy file

I want to a create directory ( eg. /tmp/staff_info ) , I will daily copy a file ( all files are different name ) to it and remove the file that over 7 days , that means this directory keep the most latest 7 days file , can advise what can i do ? thx
3 REPLIES 3
Ninad_1
Honored Contributor
Solution

Re: copy file

You can schedule a job through cron - which will have the line
find /tmp/staff_info -mtime +7 | xargs rm

Using xargs will help in not triggering too many rm commands simultaneously causing system to be loaded during that period.

The normal method would have been
find /tmp/staff_info -mtime +7 -exec rm {} \;
But I prefer the 1st method.

Regards,
Ninad
A. Clay Stephenson
Acclaimed Contributor

Re: copy file

A minor point: It is considered bad form to use /tmp for user temporary files; /tmp is for system-related temporary files. Instead, you should use /var/tmp/staff_info. Even better is to observer the TMPDIR convention which says if TMPDIR is defined use that value otherwise default to /var/tmp.
If it ain't broke, I can fix that.
Dennis Handly
Acclaimed Contributor

Re: copy file

>Ninad: But I prefer the 1st method.

The correct method is:
find /tmp/staff_info -mtime +7 -exec rm {} +

This calls rm with as many args as will fit.