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


当前回答

另一种选择是安装MSYS(它比Cygwin更轻量级)。

其他回答

如果你想使用Win32端口的一些Unix实用程序(而不是安装Cygwin),我推荐Win32的GNU实用程序。

重量比Cygwin轻,更轻便。

你可以得到尾巴作为Cygwin的一部分。

任何人对使用批处理命令(见下文)的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

安装MKS Toolkit…这样你就可以在Windows上运行所有的Unix命令。

命令如下:

tail -f <file-name>  

我使用Tail For Windows。当然没有使用tail那么优雅,但这是在使用Windows。;)