有时候我们需要把一个目录里的所有文件的修改时间变更成某个特定的时间,使用下面的方法:
# Windows下,需要使用PowerShell:
$directoryPath = "E:"
$fixedTime = Get-Date "2021-01-01 11:54:12"
Get-ChildItem -Path $directoryPath -Recurse | ForEach-Object {
$_.LastWriteTime = $fixedTime
$_.CreationTime = $fixedTime
$_.LastAccessTime = $fixedTime
}
# Linux下
find . -type f -exec touch -t 202406011530.00 {} +