Subj : Re: Can I mirror a directory on the same computer ? To : alt.comp.linux,alt.comp.os.linux,comp.os.linux From : Michael Fread Date : Sun Oct 31 2004 01:13 am Are you sure your not really just wanting to soft-link the directory? "I would like files that have been removed from the source directory to be removed from the destination directory." Someone already told you the flags for the copy, for this: ############# # Start here ############# SRCDIR=/somewhere DESTDIR=/elsewhere #Copy changed files cp -PuR $SRCDIR $DESTDIR; #Clean up deleted for FILE in `ls $DESTDIR` do if [ -f $DESTDIR/$FILE ] then if [ ! -e $SRCDIR/$FILE ] then rm -f $DESTDIR/$FILE; fi fi done ################ # End here ################ This has a few problems, mainly it doesn't cleanup subdirs. Also if someone were to delete a file in the srcdir, and then create a directory with the name of the file, it would not successfully overwrite it. I also didn't actually run this or especially double check, could be typoes and minor syntax glitches. I'll repeat again, what you really want is to rsync or to symlink this directory. Failing that, you should have the script delete the dest dir and do a full copy each time. On Sun, 31 Oct 2004 04:06:22 +0000, Mark Hobley wrote: > I want to create a script, which will run from a cron job to mirror the > contents of one directory to another. > > Both directories are on the same computer, so I don't want to use rsync, or > fmirror. > > I know that I can use cp -r. > > I would like to copy only files that differ from those in the destination > directory, and I would like files that have been removed from the source > directory to be removed from the destination directory. > > Is there a simple way of mirroring directories in this manner ? > > Thanks in advance. > > Regards, > > Mark. .