移动目录而不修改时间戳

Moo*_*oon 10 directory timestamps mv

我想将目录从一个位置移动到另一个位置,但是当我这样做时,我可以看到时间戳已更改。有没有办法将时间戳保留为原始时间戳?

查看了手册页,mv但找不到任何现有选项。

αғs*_*нιη 11

cp如下使用,mv不行。

cp -r -p /path/to/sourceDirectory /path/to/destination/
Run Code Online (Sandbox Code Playgroud)

来自人cp:

-p
    same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]
    preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all
Run Code Online (Sandbox Code Playgroud)

然后复制完成后,删除 sourceDirectory

  • 那么 `cp -r --preserve=all` 是我能得到的最好的吗? (3认同)
  • 没有据我所知,唯一的选择是使用“rsync”和“--remove-source-files”选项来仅删除_files_,但这不会删除目录本身,因此之后您还需要删除目录。 (2认同)