How to copy a directory and everything inside it while preserving permissions and timestamps

Use cp -a to copy a directory and everything inside it while preserving permissions and timestamps:

cp -a /path/to/source_dir /path/to/destination/

If the destination directory doesn’t exist, it will be created. To copy only the contents of the source directory into an existing destination:

cp -a /path/to/source_dir/. /path/to/destination/

Leave a comment