How to duplicate a folder exactly
Here I tried all the code in my Linux. Seems Rsync proposed by @seanmcl as the right one while others failed to keep owners and/or some special files or a denied result. The exact code is:
$ sudo rsync -aczvAXHS --progress /var/www/html /var/www/backup
Just remember to use just the directory name and not put a slash (/
) or a wildcard (/*
) at the end of source and target name otherwise the hidden files right below the source are not copied.
Another popular option is to use tar c source | (cd target && tar x )
. See this linuxdevcenter.com article.