用 Get-Content -Tail -Wait 实时查看日志
PowerShell 自带的 tail -f:先显示最后 N 行,日志增长时持续输出新内容。
运行 Get-Content '<日志文件>' -Tail 20 -Wait,显示最后 20 行并实时打印新增内容,按 Ctrl+C 停止。
01命令
命令
$ Get-Content 'C:\Logs\app.log' -Tail 20 -Wait02作用说明
-Wait 约每秒轮询一次文件并输出追加的行,效果等同 tail -f;-Tail 控制起始显示的行数。输出走正常管道,可以边看边过滤:... -Wait | Select-String 'ERROR'。单独使用 -Tail(不加 -Wait)也能一眼查看超大文件的末尾。
03风险
!注意: -Wait 不会自己退出,需按 Ctrl+C 停止;日志轮转时文件被删除重建,它不会跟随新文件。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Get-Content - PowerShell依据: SS64 lists -Tail and -Wait parameters, noting -Wait polls the file and outputs new lines when added.
- Get-Content | Microsoft Learn依据: Microsoft documents Get-Content -Tail <n> to return the last n lines and -Wait to keep the file open and emit new lines as they are appended.
最后验证: 2026-09-17 · 分类: 文件与文件夹