2

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.
  • Is your share mounted with the uid option set to your user? Without this, ownership and timestamp preservation wont work! – marc May 6 '16 at 11:14
  • No it was not as everyone can see in the problem description. But appending the mount command to "sudo mount -t cifs //mynas/folder /home/mnt/nas/ -o user=username -o gid=1000,uid=1000" solves the problem. Many thanks for your answer :). Wouldn't you like to write a official answer, so I could mark it at the correct answer? – Fango May 6 '16 at 16:28
0

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
  • That's true, but still with "cp -p" the "last modified" attribute changes. – Fango May 6 '16 at 11:04
0

There are several other utilities that can be used to copy files without modifying their timestamps. rsync (especially, using the '-t' flag) and cpio (using the '-m' flag) can both be used in this case. Check out the manual pages for each to see what other options might be useful.

  • It's not the fault of the tools I'm using to copying files that the time stamp is changed, it happens with all tools I tested. It has to be a layer below the application layer that causes this undesirable behavior. – Fango May 6 '16 at 15:09
  • Just tested on an smbfs mount on OSX. Using cp -p timestamps were not preserved when transferring to the smbfs mount. Using rsync -avzt timestamps were preserved correctly. So I'm leaning towards it being the tools. – Thomas N May 6 '16 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.