Jorrick Sleijster
Jorrick Sleijster

Reputation: 1156

Find command only scanning sub folders and not only copying files from the last day

I want a crontab command that at every morning checks folder /home/user/USBHD/Movies for files less then one day old and then copy them to my /home/user/NASVD/Movies with no overwriting. I tried the following but that doesn't work since it only seems to scan the subfolders and still copy all the files no matter what time they where made..

01 08 * * * /usr/bin/find /home/user/USBHD/Movies/ -mtime 1 -exec cp -n {} /home/user/NASVD/Movies \;

Anyone any idea's?

I tried the command without the cronstuff in the beginning and it didn't work as it should, like already explained.

Hope you guys can help ;)

Edit: I tried /usr/bin/find /home/user/USBHD/Movies/ -mtime +1 -exec cp -n {} /home/user/NASVD/Movies \; but that doesn't do anything at all..

EDIT:::::::::::::::::::: /usr/bin/find /home/user/USBHD/Movies/ -mtime 1 -exec cp -n {} /home/user/NASVD/Movies \;

I found the problem with this string What it should have been:

 /usr/bin/find /home/user/USBHD/Movies/ -mtime '-1' -exec cp -n {} /home/user/NASVD/Movies \;

Thanks for helping ;D

Upvotes: 0

Views: 407

Answers (1)

jim mcnamara
jim mcnamara

Reputation: 16389

/usr/bin/find /home/user/USBHD/Movies/ -mtime +1 -exec cp -n {} /home/user/NASVD/Movies \;

Two points - this will continue copying files more then 1 day old - that include 2 ,3 ,4 ... forever. Also I hope this is run in the user's crontab so that file permissions work correctly. If this is root's crontab the copied files will be owned by root. This script also does not remove day 1+ and older files it just copies them. So: as I said it will always copy any file 1+ days old.

IF you change cp to mv the file will disappear from the first directory and get moved into the second,

Upvotes: 1

Related Questions