9

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

Ch Na
  • 227

6 Answers6

10

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
waltinator
  • 37,856
9

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.
muru
  • 207,228
vanadium
  • 97,564
4
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

muru
  • 207,228
2

There is no easy way to get or set the creation time of a file in Linux. If that absolutely must be preserved, for which I don't see much point, you can fake the system time (using, for example, the aptly named faketime command) when copying the files, but you'd need to copy each entry individually, so that the time can be set for each file correctly. Even then, there might be some inaccuracy. Since getting the creation time itself is a chore, and since time can be faked pretty easily, but probably not exactly, there really isn't much point to doing so, however.

muru
  • 207,228
1

While the other answers are correct, you may want to add the file to .zip archive (maybe in addition to plain copy if it's not huge), as it will preserve timestamps better in the long term (given enough time, you data will be copied around to various storage media, restored from backups, put to and from the cloud etc. and file metadata like timestamps will eventually be lost. Being inside ZIP archive will protect it.)

Matija Nalis
  • 1,482
  • 15
  • 21
0

simply copying an archive file won't change the created dates of the files/folders in the archive

ghweq
  • 1