Hik*_*ari 8 cp date file-copy linux-kernel file-metadata
我有一个在 Linux 上运行的 Asustor NAS;我不知道他们使用什么发行版。
我可以使用 SSH 登录它并使用所有 Shell 命令。内部卷使用 ext2,外部 USB 硬盘使用 NTFS。
当我尝试使用cp
命令来复制任何文件时,该文件的日期元数据将更改为当前日期时间。
例如,如果我使用 Windows 从 SMB 复制文件并且该文件在 2007 年被修改,则新文件被标记为现在在 2017 年创建但在 2007 年修改。但使用 Linuxcp
命令其修改日期也更改为 2017 年。
这个修改日期与我非常相关,因为它允许我按修改日期对 Windows 资源管理器上的文件进行排序。如果它被覆盖,我将无法排序,而且它们现在似乎都已创建。我还使用修改日期来了解我何时获得了一些罕见的旧文件。
我可以在cp
命令中使用任何参数来保留原始文件元数据吗?
更新:我试过了,cp --preserve=timestamps
但没有用,它打印了:
cp: unrecognized option '--preserve=timestamps'
BusyBox v1.19.3 (2017-03-22 17:23:49 CST) multi-call binary.
Usage: cp [OPTIONS] SOURCE DEST
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY
-a Same as -dpR
-R,-r Recurse
-d,-P Preserve symlinks (default if -R)
-L Follow all symlinks
-H Follow symlinks on command line
-p Preserve file attributes if possible
-f Overwrite
-i Prompt before overwrite
-l,-s Create (sym)links
Run Code Online (Sandbox Code Playgroud)
如果我尝试只是-p
它说cp: can't preserve permissions of '...': Operation not permitted
,但据我测试,时间戳被保留。
roa*_*ima 13
如果您man cp
过去阅读复制命令的手册页,您会发现这些-p and --preserve
标志。
-p
与...一样--preserve=mode,ownership,timestamps
和
--preserve[=ATTR_LIST]
保留指定的属性(默认值:)mode,ownership,timestamps
,如果可能的话,附加属性:context
,links
,xattr
,all
这归结为您应该使用cp -p
而不仅仅是cp
.