Copying directory trees only for new files
Giorgos Keramidas
keramida at ceid.upatras.gr
Sun Jan 9 15:40:34 PST 2005
On 2005-01-10 00:08, Anthony Atkielski <atkielski.anthony at wanadoo.fr> wrote:
> What's the safest and most elegant way to copy an entire directory tree
> such that only newer files and directories are actually copied?
cpio(1) does that by default (to overwrite files in the destination path
that are newer with older copies from the source hierarchy, you have to
force overwriting with the -u option). You can use it in `pass through'
mode to copy entire hierarchies to another place:
% gothmog:/tmp$ rm -fr newstuff
% gothmog:/tmp$ find oldstuff | xargs ls -ld
% drwxrwxr-x 4 giorgos wheel 512 Jan 10 01:34 oldstuff
% drwxrwxr-x 3 giorgos wheel 512 Jan 10 01:34 oldstuff/bar
% drwxrwxr-x 2 giorgos wheel 512 Jan 10 01:34 oldstuff/bar/baz
% -rw-rw-r-- 1 giorgos wheel 12 Jan 10 01:34 oldstuff/bar/baz/kazaam
% drwxrwxr-x 3 giorgos wheel 512 Jan 10 01:34 oldstuff/foo
% drwxrwxr-x 2 giorgos wheel 512 Jan 10 01:34 oldstuff/foo/bar
% -rw-rw-r-- 1 giorgos wheel 12 Jan 10 01:35 oldstuff/foo/bar/xyz
% gothmog:/tmp$ cp -Rp oldstuff newstuff
% gothmog:/tmp$ touch oldstuff/bar/baz/kazaam
% gothmog:/tmp$ ( cd oldstuff ; find . | cpio -p -dmv /tmp/newstuff )
% /tmp/newstuff/./foo
% /tmp/newstuff/./foo/bar
% cpio: /tmp/newstuff/./foo/bar/xyz not created: newer or same age version exists
% /tmp/newstuff/./bar
% /tmp/newstuff/./bar/baz
% /tmp/newstuff/./bar/baz/kazaam
% 1 block
% gothmog:/tmp$
Note that foo/bar/xyz is skipped, since it didn't change, but
bar/baz/kazaam is copied because it was touched.
- Giorgos
More information about the freebsd-questions
mailing list