[SOLVED] Preserving copy file timestamps

ForeverNoob

New Member
Joined
Mar 30, 2021
Messages
18
Reaction score
6
Credits
153
Hello,

When copying a file from my local PC disk to a NAS drive (WDMyCloud) the new copy receives current timestamp. When trying this:

Code:
cp --preserve=timestamps ~/MyNotes/filename /mnt/nas/Temp/filename

An error message says:

Code:
cp: preserving times for '/mnt/nas/Temp/filename': Operation not permitted

Any clues on how to do this?

TIA
 


Code:
cp -p filename /another/place/
will generally suffice to keep all of mode, ownership and timestamp for the copied file in its new location if that new location is in the user's /home/user filesystem. In your case copying a file to /mnt is a case of copying to the root filesystem where one needs root permissions to copy and manipulate files. The main exception to that is copying or writing a file to /tmp which anyone can usually do.
 
Last edited:
Code:
cp -p filename /another/place/
will generally suffice to keep all of mode, ownership and timestamp for the copied file in its new location if that new location is in the user's /home/user filesystem. In your case copying a file to /mnt is a case of copying to the root filesystem where one needs root permissions to copy and manipulate files. The main exception to that is copying or writing a file to /tmp which anyone can usually do.
I have a partition mounted as /mnt/data, and files copied to it with timestamp preserved, no need for sudo.
 
ForeverNoob wrote:
I have a partition mounted as /mnt/data, and files copied to it with timestamp preserved, no need for sudo.

Alas:
Code:
[flip@jad ~]$ ls -al /mnt
total 8
drwxr-xr-x  2 root root 4096 Nov 22  2021 .
drwxr-xr-x 19 root root 4096 Oct  7 17:37 ..
[flip@jad ~]$ cp filename /mnt
cp: cannot create regular file '/mnt/filename': Permission denied

This is a debian system. If a filesystem or device has been mounted on /mnt users can usually access those, given permissions having been set for that to occur. Access from a GUI environment that uses polkit permissions may allow user access to /mnt. In the case of ordinary shell access though, without polkit permissions, the outcome in the output above has been the default. A permission change from default could change matters. The OP appeared to be just using the shell.
 
Last edited:
OK, I see now that the owner of everything under /mnt/data is my user, while under /mnt/nas is root. I created a test folder under /mnt/nas and then:
Code:
sudo chown myuser /mnt/nas/test
No error message, but the owner of the test folder didn't change and it is still root.
 

Members online


Latest posts

Top