Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm still kind of new to Linux, but here's what I'm trying to do.

I need to copy all subdirectories and files from one directory to another ever 5 minutes or so, with the old data automatically being overwritten with the new data.

I'd also like this to run at startup. Is there any way this can be done? If so, what program would I need to schedule the automation and what is the command line I would need.

share|improve this question
Also because it makes the site work better (that's the real reason..) – intuited Jun 11 '10 at 15:55
up vote 5 down vote accepted

I would do the actual copy with

rsync --archive --delete "fromdir/" "todir/"

This is going to be more efficient than using cp, since rsync only copies files that have changed, and even then only copies over the change itself, rather than the entire file.

If you prefer that it not delete files in todir that have been deleted in fromdir, you just leave out the --delete option.

The --archive option basically tells it to preserve the state of the files as well as their content. Note that if you have any symbolic links in dir1, this will copy the links themselves, and not the files they link to. Using this flag with rsync is similar to using cp -a.

Make sure you use the closing slash on fromdir/: this tells rsync to copy the contents of that directory, rather than the directory itself. In other words, if you leave out the final /, you will end up with


rather than

share|improve this answer
+1 for improving my answer! – BloodPhilia Jun 11 '10 at 8:00
+1 for cooperation! Actually I can't, I already voted your answer up at the beginning. – intuited Jun 11 '10 at 15:54

You need to put a script in cron, how to do this, read here:

Instead of a script, you could type a command to execute in your crontab, it would look like:

*/5 * * * * cp -r /fromdir /todir

also add to /etc/crontab the following line to exexute it at boot:

@reboot root cp -r /fromdir /todir
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.