Prevent updates to ‘modified time’ when copying files to a mounted Samba folder

file-copymountsambatimestamps

I don’t want the “last modified” attribute to be changed to the current date when copying files to a mounted Samba folder. How can I do this?

This behavior occurs with (K)Ubuntu 12.04 and Ubuntu 15.10. It can be reproduced using GUI browsers (tested with nautilus 3.4.2 and dolphin 2.0) and using cp -p in terminal.

The Samba folder was mounted to the local file system either with:

  • sudo mount -t smbfs //mynas/folder /mnt/nas/ -o user=username

or

  • sudo mount -t cifs //mynas/folder /home/mnt/nas/ -o user=username.

Notes:

  • When connecting to the same Samba folder (either with nautilus or dolphin) using a URL like smb://username@mynas/folder/, then I can copy files to it without having the “modified time” replaced with the current time!
  • But mounting a Samba folder is more convenient, also not all tools support the smb protocol. This is why using the URI smb:// is not a workaround for me.

Best Answer

The command cp -P doesn't apply to your needs. You are using uppercase argument letter -P which is used to never follow symbolic links.

What you want to use is lowercase to preserve timestamps: cp -p


As described in the comment section of the question, using the correct gid and uid solved the problem:

sudo mount -t cifs //mynas/folder /home/mnt/nas/ -o user=username -o gid=1000,uid=1000
Related Question