Monday, April 11, 2011

Recursively copying files along with directory structure in linux

Although this is something relatively simple, sometimes doesnt work correctly especially if you're trying it after a long time. You could be faced with errors like :

cp: cannot create symbolic link , etc.

If you wanna copy say, multiple files along with directory structure from
/ab/cd/ef/gh/ij/kl/mn/op/qr/st/uv/*

to

/aba/cdc/efe/ghg/iji/klk/mnm/opo/qrq/sts/uvu/*

then typically

cp -R /ab/cd/ef/gh/ij/kl/mn/op/qr/st/uv/ /aba/cdc/efe/ghg/iji/klk/mnm/opo/qrq/sts/uvu/

should work good for you.

The entire list of files along with the directory structure, gets copied at the destination location. It is important here to give the complete paths for source as well as destination instead of trying to use relative paths!

No comments: