我正在寻找Unix 'tail'命令的等效,这将允许我观察日志文件的输出,而它正在被写入。
当前回答
我写了这个批处理脚本。它不像Unix的“尾巴”那么复杂,但希望有人可以添加它来改进它,比如将输出限制在文件的最后10行,等等。如果你确实改进了这个脚本,请发送给我在抢劫~[at]~ gmail.com。
@echo off
:: This is a batch script I wrote to mimic the 'tail' UNIX command.
:: It is far from perfect, but I am posting it in the hopes that it will
:: be improved by other people. This was designed to work on Windows 7.
:: I have not tested it on any other versions of Windows
if "%1" == "" goto noarg
if "%1" == "/?" goto help
if "%1" == "-?" goto help
if NOT EXIST %1 goto notfound
set taildelay=%2
if "%taildelay%"=="" set taildelay=1
:loop
cls
type %1
:: I use the CHOICE command to create a delay in batch.
CHOICE /C YN /D Y /N /T %taildelay%
goto loop
:: Error handlers
:noarg
echo No arguments given. Try /? for help.
goto die
:notfound
echo The file '%1' could not be found.
goto die
:: Help text
:help
echo TAIL filename [seconds]
:: I use the call more pipe as a way to insert blank lines since echo. doesnt
:: seem to work on Windows 7
call | more
echo Description:
echo This is a Windows version of the UNIX 'tail' command.
echo Written completely from scratch by Andrey G.
call | more
echo Parameters:
echo filename The name of the file to display
call | more
echo [seconds] The number of seconds to delay before reloading the
echo file and displaying it again. Default is set to 1
call | more
echo ú /? Displays this help message
call | more
echo NOTE:
echo To exit while TAIL is running, press CTRL+C.
call | more
echo Example:
echo TAIL foo 5
call | more
echo Will display the contents of the file 'foo',
echo refreshing every 5 seconds.
call | more
:: This is the end
:die
其他回答
你可以得到尾巴作为Cygwin的一部分。
我想我已经找到了一个实用程序,可以满足批处理文件中尾函数的需求。它叫做“mtee”,是免费的。我已经把它合并到我正在处理的批处理文件中,它做得非常好。只要确保将可执行文件放到PATH语句中的一个目录中,就可以了。
这是链接:
mtee
图形化日志查看器虽然可能非常适合查看日志文件,但不能满足可以合并到脚本(或批处理文件)中的命令行实用程序的需求。通常,这样一个简单的通用命令可以作为特定环境的专门解决方案的一部分使用。图形化方法并不适合这种用途。
我最近使用了Mtail,它似乎工作得很好。这就是上面提到的像baretail一样的GUI类型。
我写了这个批处理脚本。它不像Unix的“尾巴”那么复杂,但希望有人可以添加它来改进它,比如将输出限制在文件的最后10行,等等。如果你确实改进了这个脚本,请发送给我在抢劫~[at]~ gmail.com。
@echo off
:: This is a batch script I wrote to mimic the 'tail' UNIX command.
:: It is far from perfect, but I am posting it in the hopes that it will
:: be improved by other people. This was designed to work on Windows 7.
:: I have not tested it on any other versions of Windows
if "%1" == "" goto noarg
if "%1" == "/?" goto help
if "%1" == "-?" goto help
if NOT EXIST %1 goto notfound
set taildelay=%2
if "%taildelay%"=="" set taildelay=1
:loop
cls
type %1
:: I use the CHOICE command to create a delay in batch.
CHOICE /C YN /D Y /N /T %taildelay%
goto loop
:: Error handlers
:noarg
echo No arguments given. Try /? for help.
goto die
:notfound
echo The file '%1' could not be found.
goto die
:: Help text
:help
echo TAIL filename [seconds]
:: I use the call more pipe as a way to insert blank lines since echo. doesnt
:: seem to work on Windows 7
call | more
echo Description:
echo This is a Windows version of the UNIX 'tail' command.
echo Written completely from scratch by Andrey G.
call | more
echo Parameters:
echo filename The name of the file to display
call | more
echo [seconds] The number of seconds to delay before reloading the
echo file and displaying it again. Default is set to 1
call | more
echo ú /? Displays this help message
call | more
echo NOTE:
echo To exit while TAIL is running, press CTRL+C.
call | more
echo Example:
echo TAIL foo 5
call | more
echo Will display the contents of the file 'foo',
echo refreshing every 5 seconds.
call | more
:: This is the end
:die
推荐文章
- 如何在命令提示符中使用空格?
- 在Python中如何在Linux和Windows中使用“/”(目录分隔符)?
- 命令行从操作系统级配置中删除环境变量
- 在特定的文件夹中打开Cygwin
- 命令行svn for Windows?
- Gulp命令未找到-安装Gulp后错误
- 如何找到并运行keytool
- 我的Windows应用程序的图标应该包括哪些大小?
- 在Windows上设置Python simpleHTTPserver
- 如何从批处理文件运行PowerShell脚本
- 使用“start”命令并将参数传递给已启动的程序
- 无法在打开用户映射区段的文件上执行所请求的操作
- 如何编写多行命令?
- 在安装了Resharper的Visual Studio中,键盘快捷键不活跃
- 如何配置OpenFileDialog来选择文件夹?