如何保留文件的原始创建日期?

76

我正在使用文件管理器将服务器上的文件从一个目录移动到另一个目录。有没有办法保留文件创建日期/时间(即首次添加到服务器时的时间)?有人建议使用SSH,但我对其不是很熟悉。是否有人能够提供一些好的指导?


Stack Overflow是一个关于编程和开发问题的网站。这个问题似乎不属于编程或开发范畴。请参阅帮助中心中的我可以在这里问什么样的问题。也许超级用户Unix&Linux Stack Exchange更适合提问。 - jww
3个回答

132

使用带有-p选项的scp命令。

 -p      Preserves modification times, access times, and modes from the original file.

将文件从本地复制到远程服务器的示例命令:

scp -p /home/mylocaldata/test.txt remote.example.com:/home/remote_dir
请注意,这将不会保留用户和组的权限标志(例如rwx等)。

1
尝试访问此网站http://www.hypexr.org/linux_scp_help.php。SCP通常随Linux一起提供,只需尝试命令行并键入scp即可。因此,命令如下所示。假设我需要从/home/mydata/test.txt文件传输到目标服务器x.x.x.x目录 - /home/test,则使用以下带有保留权限的命令:scp -p /home/mydata/test.txt x.x.x.x:/home/test - Tharanga Abeyseela
我本以为这是默认设置;我甚至在~/.bashrc中创建了一个别名:alias scp='scp -p' :) - Bikash Gyawali

10

您还可以使用-t--times选项通过SSH进行rsync同步操作

rsync -P -e ssh -t <source> <destination>

我喜欢使用-P选项(与--partial --progress相同),因为如果传输半途中停止(或失败),它不会删除所有文件,并且会报告进度。请参见rsync手册页

   -t, --times
          This  tells  rsync  to  transfer modification times along with the
          files and update them on the remote system.  Note that if this op‐
          tion  is  not used, the optimization that excludes files that have
          not been modified cannot be effective; in other words,  a  missing
          -t  or -a will cause the next transfer to behave as if it used -I,
          causing all files to be updated (though rsync’s delta-transfer al‐
          gorithm will make the update fairly efficient if the files haven’t
          actually changed, you’re much better off using -t).

0
一旦您在远程机器上设置了ssh服务器,就可以在FileZilla上执行此操作: 在传输菜单中有一个保留时间戳选项。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接