[Ilugc] Re: how to merge directory contents

  • From: sriram@xxxxxxxxxxxxx (P.Sriram)
  • Date: Tue Jan 19 18:03:49 2010

Saravanan S <dearsaravanan@...> writes:

      I need to merge the contents of several directories, into a single
directory structure,
Like i have
dir1/a/1
dir1/b/2
dir2/a/10
dir2/b/20

after merging dir1 and dir2, i should get,

dirnew/a/1 and 10
dirnew/b/2 and 20

How to do this easily?

Well, I cant believe this is still left unsolved. So, here is a (tried and 
tested) suggestion. How about using the -u option of the cp command? Like this,

cp -r dir1/* dirnew
cp -r -u dir2/* dirnew

If the * expansion dies because of the number of files, then you may have to 
write a short script with the same logic.

Sriram

Other related posts: