Copy directory in linux

Posted under others On By xpk

Back to 101, copy a directory. This sounds trivial but there are subtle differences that can make a huge difference.

I used to run this as it makes sense to me syntactically

rsync -av source/* dest/

It works well BUT all the hidden directories right below source/ will not be copied.

If I do any of the followings, source will end up being a subdirectories under dest:

rsync -av source dest

cp -ap source dest

cp -ap source/ dest

So what’s the correct way to do it? There may be a number of ways but this one works:

rsync -av source/ dest

Simple command, copies everything and preserve ownerships, permissions, and dates. 

 245 total views,  2 views today

Leave a comment

Your email address will not be published. Required fields are marked *