I have to keep copying files over from my ~/src to /home/httpd directory, which is a pain when I'm making front end changes. Is there a way I can have changed files sync automagically? -- and specifically only while I'm developing -- something I can turn on and off.
I am not entirely sure what your objective is, but a few suggestions that might be of some use:
Instant, on modification (save): If you want the files to be updated as soon as one is modified, I might ask why you don't just make your changes in /home/httpd and then once everything is to your satisfaction copy them back. The idea of a working directory for safeguards (or to prevent taking down your site with a bad edit) is negated if the changes are to be copied immediately.
Near-instant, on modification: If for some reason, you wish to have your changes applied nearly instantly, on file modification (i.e. as soon as a file is saved, it gets copied over) then I would suggest looking into
incron
. It can be set to trigger a script when a directory changes.On demand (not instant):
If you are looking to complete all your edits and then push the changes (which is what I expect you are looking for), then you have several options. I presume that the annoyance lies in determining what files were changed, and copying them from a variety of different directories.
Shell script: One simple solution to this is to use
rsync
. It will determine what the changes are in your ~/src directory relative to your /home/httpd directory, and make the changes needed to get your /home/httpd in sync with your source directory.Version Control: The most effective solution, although, considerably more complex than rsync, is version control - for instance, Subversion. Basically:
svn commit
) - the hook will automatically update /home/httpdWhile more difficult to setup, initially, this approach allows the greatest control, and will easily let you rollback changes, list the modified files, and see what changes (diffs) were made at each revision - you can also add a description to your changes with each commit.
Although not automatic, once you are done doing modifications, use rsync:
You could even create an alias:
As I emphasize to everyone, before using this you should check out
man rsync
for additional options.Also, I'd strongly suggest version control (svn or git perhaps) for a multitude of reasons.
Edit:
What I would personally do is use a
bash
loop---specificallywhile
loop with asleep
. Enter the following in the shell:This will make it a background job that you could kill at anytime. Just type
jobs
to see the index of the job and, when you do not need it anymore, typekill %(index)
.Alternatively, to add the command as a
cron
job for, e.g., every 10 minutes, append the following to your crontab:To edit your crontab:
Look at lsyncd. It uses inotify to get info about changes in files and sync them over rsync.