我正在寻找类似于Unix 'tail'命令的工具,可以在日志文件被写入时观看其输出。
我正在寻找类似于Unix 'tail'命令的工具,可以在日志文件被写入时观看其输出。
如果你使用PowerShell,那么这个会起作用:
Get-Content filenamehere -Wait -Tail 30
为了让大家不错过,这里转载 Stefan 的评论:
PowerShell 3 引入了一个 -Tail 参数,可以只包含最后的 x 行。
Get-Content -Tail 100 -Wait .\logfile.log
这样的吗? - Henno Vermeulen我建议安装类似GNU Utilities for Win32这样的东西。它包括大多数喜欢的工具,包括tail。
tail
命令,但是它卡住了。more
命令正常运行(至少能查看文件开头部分)。 - Eric J.head
命令,但无法使用tail
命令...有什么想法吗? - Alphaaa我一直在Windows上使用Baretail来进行日志追踪。它是免费的,而且非常好用。
有没有人对使用批处理命令(见下文)进行CMD尾部操作感兴趣。
它不是完美的,有时会重复行。
用法:tail.bat -d tail.bat -f -f
@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
rem tail.bat -d <lines> <file>
rem tail.bat -f <file>
rem ****** MAIN ******
IF "%1"=="-d" GOTO displayfile
IF "%1"=="-f" GOTO followfile
GOTO end
rem ************
rem Show Last n lines of file
rem ************
:displayfile
SET skiplines=%2
SET sourcefile=%3
rem *** Get the current line count of file ***
FOR /F "usebackq tokens=3,3 delims= " %%l IN (`find /c /v "" %sourcefile%`) DO (call SET find_lc=%%l)
rem *** Calculate the lines to skip
SET /A skiplines=%find_lc%-!skiplines!
rem *** Display to screen line needed
more +%skiplines% %sourcefile%
GOTO end
rem ************
rem Show Last n lines of file & follow output
rem ************
:followfile
SET skiplines=0
SET findend_lc=0
SET sourcefile=%2
:followloop
rem *** Get the current line count of file ***
FOR /F "usebackq tokens=3,3 delims= " %%l IN (`find /c /v "" %sourcefile%`) DO (call SET find_lc=%%l)
FOR /F "usebackq tokens=3,3 delims= " %%l IN (`find /c /v "" %sourcefile%`) DO (call SET findend_lc=%%l)
rem *** Calculate the lines to skip
SET /A skiplines=%findend_lc%-%find_lc%
SET /A skiplines=%find_lc%-%skiplines%
rem *** Display to screen line when file updated
more +%skiplines% %sourcefile%
goto followloop
:end
有很多选择,但它们都有一些缺陷并且更高级的功能存在问题。
GnuWin32 tail 有缺陷(α β γ),例如 -f 功能根本不起作用。
UnxUtils tail 似乎更好(-f 功能有效,但 --pid 似乎不行,-n 但没有--lines=n 不支持 -f),但似乎是一个不再维护的项目。
Cygwin 是一个庞大而丑陋的混杂物,也许可以只使用 DLL 和 coreutils 软件包 - 但仍然存在诸如 --pid 与本地 win32 进程不兼容的问题。
如果您不想安装任何东西,您可以使用标准Windows命令“构建自己”的批处理文件来完成工作。以下是如何操作的一些提示。
1)使用find /c /v "" yourinput.file,获取输入文件中行数的数量。输出类似于:
---------- T.TXT: 15
2) 使用 for /f 命令解析此输出以获取数字 15。
3) 使用 set /a 命令计算需要跳过的标题行数。
4) 使用 for /f "skip=n" 命令跳过标题行,并回显/处理尾行。
如果我有时间,我将构建这样一个批处理文件并在此处发布。
tail.bat
REM tail.bat
REM
REM Usage: tail.bat <file> <number-of-lines>
REM
REM Examples: tail.bat myfile.txt 10
REM tail.bat "C:\My File\With\Spaces.txt" 10
@ECHO OFF
for /f "tokens=2-3 delims=:" %%f in ('find /c /v "" %1') do (
for %%F in (%%f %%g) do set nbLines=%%F )
set /a nbSkippedLines=%nbLines%-%2
for /f "usebackq skip=%nbSkippedLines% delims=" %%d in (%1) do echo %%d
通过 Windows PowerShell,您可以使用:
Get-Content <file> -Wait
tail一样优雅,但毕竟你在使用Windows。;)
在这里的回答中,我没有看到任何关于Log Expert的内容。
它是可定制的,非常适合浏览日志文件。到目前为止,这是我使用过的最好的Windows图形化日志查看器。
不幸的是,这个软件已经不再提供。您可以在archive.org上阅读有关它的信息。