大网数据广告活动
服务器运维问答

cp -p will preserve times for some files but not all?

· 52CE 我爱测

I have a source directory on a machine with a bunch of files, all with the same permissions, that I want to copy to another directory, that is mounted via SMB. [tmark@dexter JR09141045 roche_454_transfer]$ ls -l /source_dir total…

问题原文

原帖链接 · tmark · CC BY-SA 3.0

I have a source directory on a machine with a bunch of files, all with the same permissions, that I want to copy to another directory, that is mounted via SMB.

[tmark@dexter JR09141045 roche_454_transfer]$ ls -l /source_dir
total 71348
-rwxrwxrwx 1 adminrig lifelabs 19768377 Mar 25 23:29 1.TCA.454Reads.fna
-rwxrwxrwx 1 adminrig lifelabs 53093396 Mar 25 23:29 1.TCA.454Reads.qual
-rwxrwxrwx 1 adminrig lifelabs     1035 Mar 25 23:29 454AllControlMetrics.csv
-rwxrwxrwx 1 adminrig lifelabs     2657 Mar 25 23:29 454AllControlMetrics.txt
-rwxrwxrwx 1 adminrig lifelabs     4607 Mar 25 23:29 454BaseCallerMetrics.csv
-rwxrwxrwx 1 adminrig lifelabs    14518 Mar 25 23:29 454BaseCallerMetrics.txt
-rwxrwxrwx 1 adminrig lifelabs      351 Mar 25 23:23 454DataProcessingDir.xml
-rwxrwxrwx 1 adminrig lifelabs      702 Mar 25 23:29 454QualityFilterMetrics.csv
-rwxrwxrwx 1 adminrig lifelabs     1609 Mar 25 23:29 454QualityFilterMetrics.txt
-rwxrwxrwx 1 adminrig lifelabs    13496 Mar 25 23:29 454RuntimeMetricsAll.csv
-rwxrwxrwx 1 adminrig lifelabs    26967 Mar 25 23:29 454RuntimeMetricsAll.txt
-rwxrwxrwx 1 adminrig lifelabs     1675 Mar 25 14:48 dataRunParams.xml
-rwxrwxrwx 1 adminrig lifelabs     7134 Mar 25 23:29 gsRunProcessor.log

The target directory is mounted via SMB and I'm trying to copy the set of files all at once.

[tmark@dexter JR09141045 target_dir]$ cd /target_dir
[tmark@dexter JR09141045 target_dir]$ cp -p /source_dir/* ./
cp: preserving times for `./454AllControlMetrics.csv': Operation not permitted
cp: preserving times for `./454AllControlMetrics.txt': Operation not permitted
cp: preserving times for `./454BaseCallerMetrics.csv': Operation not permitted
cp: preserving times for `./454BaseCallerMetrics.txt': Operation not permitted
cp: preserving times for `./454DataProcessingDir.xml': Operation not permitted
cp: preserving times for `./454QualityFilterMetrics.csv': Operation not permitted
cp: preserving times for `./454QualityFilterMetrics.txt': Operation not permitted
cp: preserving times for `./454RuntimeMetricsAll.csv': Operation not permitted
cp: preserving times for `./454RuntimeMetricsAll.txt': Operation not permitted
cp: preserving times for `./dataRunParams.xml': Operation not permitted
cp: preserving times for `./gsRunProcessor.log': Operation not permitted

[tmark@dexter JR09141045 target_dir]$ ls -l
total 71264

-rwxrwxrwx 1 tmark 1008 19768377 Mar 25 23:29 1.TCA.454Reads.fna
-rwxrwxrwx 1 tmark 1008 53093396 Mar 25 23:29 1.TCA.454Reads.qual
-rwxr-xr-x 1 tmark 1008     1035 Apr  1  2015 454AllControlMetrics.csv
-rwxr-xr-x 1 tmark 1008     2657 Apr  1  2015 454AllControlMetrics.txt
-rwxr-xr-x 1 tmark 1008     4607 Apr  1  2015 454BaseCallerMetrics.csv
-rwxr-xr-x 1 tmark 1008    14518 Apr  1  2015 454BaseCallerMetrics.txt
-rwxr-xr-x 1 tmark 1008      351 Apr  1  2015 454DataProcessingDir.xml
-rwxr-xr-x 1 tmark 1008      702 Apr  1  2015 454QualityFilterMetrics.csv
-rwxr-xr-x 1 tmark 1008     1609 Apr  1  2015 454QualityFilterMetrics.txt
-rwxr-xr-x 1 tmark 1008    13496 Apr  1  2015 454RuntimeMetricsAll.csv
-rwxr-xr-x 1 tmark 1008    26967 Apr  1  2015 454RuntimeMetricsAll.txt
-rwxr-xr-x 1 tmark 1008     1675 Apr  1  2015 dataRunParams.xml
-rwxr-xr-x 1 tmark 1008     7134 Apr  1  2015 gsRunProcessor.log

Note that the times and permissions on the first two files are the same as in the source directory, but differ for the remaining files.

So, it seems that I can copy some files and preserve their permissions and times, but not with other files, even though all the source files come from the same place and have the same permissions and (more or less) times, and I'm copying them all to the same directory at the same time - and hence with the same umask, etc.

So, why can I preserve the times for some, but not all files ?

I'd be happy to provide more details (umask, Linux version, smb.conf, etc etc.) except I can't understand how any of those details could explain what I'm seeing - as they ought to be constant here.

社区高分解答

原帖链接 · krisFR · CC BY-SA 3.0

On Unix the timestamps cannot be preserved on the files the user does not own.

This is why the following command fails if file1 and file2 are owned by different users in case file2 already exists:

cp -p file1 file2

Seems it is your case because source files are owned by adminrig and target files are owned by tmark.

Not sure if there is a workaround as forcing with -f does not solve the issue.

If you can, try changing ownership of target files...

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-04-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。