我正在使用文件管理器将服务器上的文件从一个目录移动到另一个目录。有没有办法保留文件创建日期/时间(即首次添加到服务器时的时间)?有人建议使用SSH,但我对其不是很熟悉。是否有人能够提供一些好的指导?
我正在使用文件管理器将服务器上的文件从一个目录移动到另一个目录。有没有办法保留文件创建日期/时间(即首次添加到服务器时的时间)?有人建议使用SSH,但我对其不是很熟悉。是否有人能够提供一些好的指导?
使用带有-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等)。alias scp='scp -p'
:) - Bikash Gyawali您还可以使用-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).