How can I copy a folder without altering their original dates of creation? [duplicate]

I found an old archive filled with old folders on my pc. I would like to know how to make a copy of this archive, but keeping everything intact, including their date of creation


Read man cp, and, in addition to the --recursive switch use one of:

   -p     same as --preserve=mode,ownership,timestamps

   --preserve[=ATTR_LIST]
          preserve the specified attributes (default: mode,ownership,timestamps), if possible
          additional attributes: context, links, xattr, all

As indicated in the other answers, you need to use the terminal if you want to preserve every file attribute. However, I would suggest to use the -a (--archive) option with the cp command, which is specifically aimed at creating an identical archive copy.

cp -a <source> <destination>

The same can be achieved with the rsync utility, the local and remote file copy tool that may perform faster than cp. It also uses the option -a for the same purpose.

rsync -a <source> <destination>

For example, to copy a folder Archive in your home folder to an external USB drive mounted under /media/$USER/USB_drive:

cp -a /home/$USER/Archive /media/$USER/USB_drive/

or

rsync  -a /home/$USER/Archive /media/$USER/USB_drive/
  • Both commands will create a folder Archive containing all your subfolders and files in the existing destination folder /media/$USER/USB_drive/.
  • You can find where your USB drive is mounted in the output of the command mount | grep /media
  • You can leave $USER in place if it is for your current user. This variable is automatically substituted by your login name.

sudo cp -rp /home/my_home /media/backup/my_home

Or

sudo cp -a /home/my_home /media/backup/my_home

This should do it.

  • -r is recursive

  • -p is preserve-mode