Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Removing extraneous files from a directory mirror

11 views
Skip to first unread message

Don Kuenz

unread,
Sep 7, 2012, 11:25:19 AM9/7/12
to
My FreeBSD host contains two directories /u and /disk2/u. The latter
directory, /disk2/u ought to mirror the former directory, /u, but
extraneous files now exist on /disk2/u. This script shows what needs
to be done:

#!/bin/sh
#
# make /disk2/u a mirror image of /u by removing extraneous files.
#
cd /disk2/u
for file in `find . -type f`
do
if [ ! -f "/u/$file" ] ; then
rm /disk2/u/$file
fi
done

My gut tells me that something faster is needed and that $file is
likely to "blow up" from receiving too many names during the find
phase.

Can anybody think of a better way of doing this? By using find's
exec argument, for instance, to fully process (remove) a given
file name before moving on to the next file name?

TIA.

--
Don Kuenz

Aragorn

unread,
Sep 7, 2012, 11:30:51 AM9/7/12
to
On Friday 07 September 2012 17:25, Don Kuenz conveyed the following to
comp.unix.shell...
What about rsync? It is perfectly capable of doing the mirroring for
you.

--
= Aragorn =
(registered GNU/Linux user #223157)

Thomas 'PointedEars' Lahn

unread,
Sep 7, 2012, 1:55:39 PM9/7/12
to
Don Kuenz wrote:

> My FreeBSD host contains two directories /u and /disk2/u. The latter
> directory, /disk2/u ought to mirror the former directory, /u, but
> extraneous files now exist on /disk2/u. This script shows what needs
> to be done:
>
> #!/bin/sh
> #
> # make /disk2/u a mirror image of /u by removing extraneous files.
> #
> cd /disk2/u
> for file in `find . -type f`
> do
> if [ ! -f "/u/$file" ] ; then
> rm /disk2/u/$file
> fi
> done
>
> My gut tells me that something faster is needed and that $file is
> likely to "blow up" from receiving too many names during the find
> phase.
>
> Can anybody think of a better way of doing this?

rsync --delete $more_options $source $destination

F'up2 comp.os.unix.shell¹

______
¹ I was wrong. There is de.comp.os.unix.apps.misc, but no
comp.os.unix.apps.misc. Short of comp.unix.shell, where
would you discuss GNU or GPL-based programs such as rsync(1)?
--
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Dave Gibson

unread,
Sep 7, 2012, 3:50:54 PM9/7/12
to
Don Kuenz <gar...@crcomp.net> wrote:
> My FreeBSD host contains two directories /u and /disk2/u. The latter
> directory, /disk2/u ought to mirror the former directory, /u, but
> extraneous files now exist on /disk2/u. This script shows what needs
> to be done:
>
> #!/bin/sh
> #
> # make /disk2/u a mirror image of /u by removing extraneous files.
> #

> Can anybody think of a better way of doing this?

mtree -p /u -c | mtree -p /disk2/u -r

[ Followup-To: set to cubfm ]

Stuart Barkley

unread,
Sep 8, 2012, 2:16:23 PM9/8/12
to
On Fri, 7 Sep 2012 at 11:25 -0000, Don Kuenz wrote:

> My FreeBSD host contains two directories /u and /disk2/u. The latter
> directory, /disk2/u ought to mirror the former directory, /u, but
> extraneous files now exist on /disk2/u.

> Can anybody think of a better way of doing this?

A couple others suggested rsync. Here is a sample command that I use
to mirror my local media collection to a second drive.

rsync -n --stats -vi -aHh -P --delete /data/media/. /media/4gh-media/media/

The '-n' option enables dry-run mode where needed changes are only
reported, not performed. This allows me to double check large updates
before being applied.

I also occasionally add the '-c' option which checksums the files to
better detect any bit rot in the mirror.

If mirroring onto a FAT/NTFS drive (so the drive can be read by my TV,
etc) you may also need options "--no-g --no-p --modify-window=2".

Stuart
--
I've never been lost; I was once bewildered for three days, but never lost!
-- Daniel Boone
0 new messages