ext4 将文件复制到目录而不更改目录时间戳
ext4 copy file to directory without changing directory timestamp
我想将一个文件复制到一个目录,而不更改 ext4 文件系统上目录的修改时间戳。好吧,脚本中有很多文件和目录。
我查看了 rsync 和 cp 选项。
所以要提出问题,我如何在 ext4 文件系统上复制文件并在目标目录上保留时间戳?
有很多方法可以复制文件并保留其属性,但它们会修改父目录时间戳。需要的是记录该时间戳并在复制后应用它的两步过程。所引用的问题没有解决这个问题。 Giving a file/directory the same modification date as another
看到这个 guid。如果您想保留原始时间戳,请使用
$ touch -r <original_file> <new_file>
.
这从另一个文件复制属性。如果您需要更改特定属性,请使用以下内容。
对于访问时间
$ touch -a --date="1988-02-15" file.txt
为修改时间:
$ touch -m --date="2020-01-20" file.txt
要查看文件或文件夹的统计信息,请使用 stat <file>
$ cp --preserve=timestamps oldfile newfile
或
$ cp -p oldfile newfile
会那样做。 Man 页面明确指出。
一个选项是保存和恢复时间戳:
# Save current modification time
timestamp=$(stat -c @%Y mydir)
[.. copy/sync files ..]
# Restore that timestamp
touch -d "$timestamp" mydir
我想将一个文件复制到一个目录,而不更改 ext4 文件系统上目录的修改时间戳。好吧,脚本中有很多文件和目录。
我查看了 rsync 和 cp 选项。
所以要提出问题,我如何在 ext4 文件系统上复制文件并在目标目录上保留时间戳?
有很多方法可以复制文件并保留其属性,但它们会修改父目录时间戳。需要的是记录该时间戳并在复制后应用它的两步过程。所引用的问题没有解决这个问题。 Giving a file/directory the same modification date as another
看到这个 guid。如果您想保留原始时间戳,请使用
$ touch -r <original_file> <new_file>
.
这从另一个文件复制属性。如果您需要更改特定属性,请使用以下内容。
对于访问时间
$ touch -a --date="1988-02-15" file.txt
为修改时间:
$ touch -m --date="2020-01-20" file.txt
要查看文件或文件夹的统计信息,请使用 stat <file>
$ cp --preserve=timestamps oldfile newfile
或
$ cp -p oldfile newfile
会那样做。 Man 页面明确指出。
一个选项是保存和恢复时间戳:
# Save current modification time
timestamp=$(stat -c @%Y mydir)
[.. copy/sync files ..]
# Restore that timestamp
touch -d "$timestamp" mydir