使用 Powershell 刪除N天前的文件
在 Linux 中刪除N天前的文件可以使用以下命令:
find /path/to -maxdepth 1 -name "filename" -mtime +1 -delete
在 Windows 服務器中使用 Powershell 的命令也是類似的。
通過查詢手冊可以得到以下命令:
Get-ChildItem -Path X:\path\to | Where-Object LastWriteTime -le (Get-Date).AddDays(-2) | Remove-Item
如果需要遞歸,可以加上 -Recurse 參數;如果需要過濾文件名,可以使用 -Filter 參數
參考鏈接:
Get-ChildItem 命令文檔
Where-Object 命令文檔
Remove-Item 命令文檔
windows 下powershell中類似find命令的替代

浙公網安備 33010602011771號