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
-
3Note that most Linux filesystems don't store dates of creation — the best you can have is date of last modification. – Ruslan Oct 19 '18 at 15:51
-
1@Ruslan most do, it's just hasn't been accessible via kernel APIs until the statx call got merged. And even then, I don't think the creation time can be set manually. – muru Oct 19 '18 at 20:20
-
2@muru so, we can't actually copy a file preserving its date of creation in the copy, can we? If we can't, then this attribute is useless: it's then the date of creation of the inode, not of the document. – Ruslan Oct 19 '18 at 22:06
-
1This question is NOT a duplicate as @muru indicated, because the other question do not address this problem the ctime attribute. Please do not forget that this question is searched by other people who do not make assumptions about what the asking person really wanted, but are only interested in what the question asks. By the way, the question was addressed here : https://stackoverflow.com/questions/16126992/setting-changing-the-ctime-or-change-time-attribute-on-a-file/17066309#17066309 – Camion Jun 10 '19 at 07:14
6 Answers
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

- 36,399
-
1This will not preserve the original creation time (in fact, the last status change time). Only the last modification time will be preserved. – Camion Jun 10 '19 at 05:55
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.
-
Beware: if you use tab completion, you may unthinkingly leave a trailing slash on the source directory, which will do quite a different action. (Specifically, it would copy all the contents of
/home/$USER/Archive/
into/media/$USER/USB_drive/
rather than making a new subdirectory.) The commands as shown are correct; I just want to emphasize that adding a trailing slash to the source is not equivalent. – Wildcard Oct 22 '18 at 18:10
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

- 197,895
- 55
- 485
- 740

- 430
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.

- 197,895
- 55
- 485
- 740
-
I think the OP just wants to have the output of
ls -l
show the same timestamps for source and target (without actually knowing or being interested in what those timestamps precisely refer to). Yet +1 for explaining the background. – PerlDuck Oct 19 '18 at 20:48 -
@PerlDuck in that case it would be a dupe of https://askubuntu.com/questions/1040885/copy-file-and-keep-same-timestamp-of-original-file or other such questions – muru Oct 19 '18 at 21:20
-
-
There is certainly a point of doing so for backup and restore purposes, of if you want to transfer a whole hierarchy to another file system without loosing that info. And by the way, to avoid the precision problem you might want to proceed in two steps : 1/ copy the filesystem, 2/ change the status file per file with faketime. – Camion Jun 10 '19 at 07:09
-
however for access https://askubuntu.com/questions/62492/how-can-i-change-the-date-modified-created-of-a-file ... – ntg Jun 15 '22 at 15:56
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.)

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

- 1
-
2Likely the OP is referring to an old archive folder, not to an archive file – vanadium Oct 19 '18 at 14:09