How to avoid the change of timestamp of files when moving then from directory

When I move files from one directory to another, the timestamp of the files changes. For example, if the file was created with a date 2013-01-01, when I move it to a different directory, the final file will have the date of the move, not of the creation.

How to fix this?


Solution 1:

  • cp -r -p SOURCE DESTINATION
  • cp -r --preserve=mode,ownership,timestamps SOURCE DESTINATION

These two commands do the same thing. The Second allows you to chose what remains the same. I am not aware of a way of specifically doing this with mv, but I believe this is mvs default behavior.

Alternatively, you could try copying hard-links, which is much more similar to mv, as suggested here:

  • cp -p -r -l source/date target/

I believe the problem you are experiencing is due to an ntfs/fat partition? If this is true, try setting up a rule in /etc/fstab that uses your uid.