There are several different way to copy all the files in one folder to another, while preserving the file permissions and attributes.
Not every method will copy hidden files and some are definitely easier to remember than others…
The GNU version of the copy command can copy sub-folders and can preserve file permissions and ownership. It is the easiest to remember, but may is not available in all versions of UNIX/Linux. Using a wildcard to specify the source file names will copy everything from the source folder to the destination folder itself but it will NOT copy any hidden files.
$ cp -rpdv /source/* /dest/
Copy allows you to use relative or full pathnames for the source and destination folders, and the destination pathname may or may not end with a backslash.
-r : Copy sub directories. -p : Preserve file attributes. -d : Don't deference (preserves links). -v : Verbose.
Should work on almost any UNIX/Linux system, providing there is enough space in /var for any intermediate pipes, and it will copy any hidden files and sub-folders.
$ pushd $(pwd) $ cd /source/;tar -cpf - . | (cd /dest/; tar xvf -) $ popd
Should work on most Linux systems, but do not expect this to work on all flavors of UNIX. However, it will copy any hidden files and sub-folders.
$ rsync -acP /source/ /dest
-a : Archive mode (equivalent to -rlptgoD). -r : Copy sub directories. -l : Copy symbolic links as symbolic links. -p : Preserves file permissions. -t : Preserves file modification timestamps. -g : Preserves group. -o : Preserves ownership. -D : Preserves device and special files. -c : Copy files based on their checksum not modification dates. -P : Keep partial file copies and show progress (since rsync performs a differential copy keeping any partially copied files on the destination should make speed up the subsequent transfer of the rest of the file).
Note – There is no backslash on the destination folder name.