softlinks atime and mtime modification

隐身守侯 提交于 2019-12-10 18:29:55

问题


Is it possible to change the atime and mtime of a symlink?

I am trying to change it using the utime() function(C code) but instead it changes the time of destination files.

Also if I do

cp -dpr <src fldr> <<dest folder> (command line) 

[The src folder contains different symlinks.] the symlinks at destination are created with current timestamp.

Doing a stat() on the symlink will give me the timing of destination file (in C code) but if we fire a stat command on command line it gives the timestamp of link(possibly it is using lstat)

Any ideas?


回答1:


You can use touch with the -h flag in bash to modify the mtime and atime of the symlink instead of the file it references:

touch -h somesymlink

You can use the -t flag to specify a time to set it to, if you don't want to use the current time.




回答2:


Use lutimes instead. See man lutimes or http://www.gnu.org/software/libc/manual/html_node/File-Times.html



来源:https://stackoverflow.com/questions/10119242/softlinks-atime-and-mtime-modification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!