我正在寻找Unix 'tail'命令的等效,这将允许我观察日志文件的输出,而它正在被写入。


当前回答

在Far Manager中,在文件上按F3进入标准查看器,然后按End键导航到文件末尾。

如果文件更新了,Far Manager将自动滚动它。

其他回答

如果你使用PowerShell,那么这是有效的:

Get-Content filenamehere -Wait -Tail 30

把Stefan的评论贴在下面,这样大家就不会错过了

PowerShell 3引入了-Tail参数,只包含最后x行

任何人对使用批处理命令(见下文)的DOS CMD尾部感兴趣。

它不是完美的,有时台词会重复。

用法:tail.bat -d 尾巴,蝙蝠-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

图形化日志查看器虽然可能非常适合查看日志文件,但不能满足可以合并到脚本(或批处理文件)中的命令行实用程序的需求。通常,这样一个简单的通用命令可以作为特定环境的专门解决方案的一部分使用。图形化方法并不适合这种用途。

在Far Manager中,在文件上按F3进入标准查看器,然后按End键导航到文件末尾。

如果文件更新了,Far Manager将自动滚动它。

DOS没有尾部指令;你可以在这里下载GNU tail和其他GNU工具的Windows二进制文件。