相当于 Unix tail 命令的 Windows

发布于 2024-07-19 09:16:06 字数 1734 浏览 4 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(26

相思故 2024-07-26 09:16:07

安装MKS Toolkit...以便您可以在Windows上运行所有Unix命令。

命令是:

tail -f <file-name>  

Install MKS Toolkit... So that you can run all Unix commands on Windows.

The command is:

tail -f <file-name>  
栀子花开つ 2024-07-26 09:16:07

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

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

In Far Manager, press F3 on a file to enter the standard viewer, then the End key to navigate to the end of file.

If the file is updated, Far Manager will scroll it automatically.

万劫不复 2024-07-26 09:16:07

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

Graphical log viewers, while they might be very good for viewing log files, don't meet the need for a command line utility that can be incorporated into scripts (or batch files). Often such a simple and general-purpose command can be used as part of a specialized solution for a particular environment. Graphical methods don't lend themselves readily to such use.

触ぅ动初心 2024-07-26 09:16:07

您也可以尝试 WinTail

??

You can try WinTail as well.

ََ

两个我 2024-07-26 09:16:07

我想我已经找到了一个实用程序,可以满足批处理文件中尾部功能的需求。 它被称为“mtee”,并且是免费的。 我已将其合并到我正在处理的批处理文件中,并且它的工作效果非常好。 只需确保将可执行文件放入 PATH 语句中的目录中即可。

这是链接:

mtee

I think I have found a utility that meets the need for the tail function in batch files. It's called "mtee", and it's free. I've incorporated it into a batch file I'm working on and it does the job very nicely. Just make sure to put the executable into a directory in the PATH statement, and away you go.

Here's the link:

mtee

巾帼英雄 2024-07-26 09:16:07

我正在使用 Kiwi 日志查看器。 免费。

I'm using Kiwi Log Viewer. It's free.

梦在夏天 2024-07-26 09:16:06

如果您使用 PowerShell,那么这有效:

Get-Content filenamehere -Wait -Tail 30

从下面发布 Stefan 的评论,这样人们就不会错过它

PowerShell 3 引入了 -Tail 参数以仅包含最后 x 行

If you use PowerShell then this works:

Get-Content filenamehere -Wait -Tail 30

Posting Stefan's comment from below, so people don't miss it

PowerShell 3 introduces a -Tail parameter to include only the last x lines

〆一缕阳光ご 2024-07-26 09:16:06

我建议安装诸如GNU Utilities for Win32之类的东西。 它有最喜欢的东西,包括尾巴。

I'd suggest installing something like GNU Utilities for Win32. It has most favourites, including tail.

过期情话 2024-07-26 09:16:06

我一直使用 Baretail 在 Windows 中进行拖尾。 它是免费的而且非常好。

I've always used Baretail for tailing in Windows. It's free and pretty nice.

你的呼吸 2024-07-26 09:16:06

您可以将 tail 作为 Cygwin 的一部分获取。

You can get tail as part of Cygwin.

烦人精 2024-07-26 09:16:06

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

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

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

Anybody interested in a DOS CMD tail using batch commands (see below).

It's not prefect, and lines sometime repeat.

Usage: 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
顾北清歌寒 2024-07-26 09:16:06

有相当多的选项,但是它们都具有更高级功能的缺陷。

  • GnuWin32 tail 有错误(α β γ) - 像 -f 这样的东西只是简单的不起作用。

  • UnxUtils tail 似乎更好(-f 有效,但 --pid 似乎无效,-n 但不是 --lines=n 因 -f) 失败,但似乎是一个死项目。

  • Cygwin 是一个丑陋的大烂摊子,也许可以只使用 DLL 和 coreutils 包 - 但仍然存在诸如 --pid 不适用于本机 win32 进程之类的问题。

There are quite a number of options, however all of them have flaws with more advanced features.

  • GnuWin32 tail is buggy (α β γ) - things like -f just plain don't work.

  • UnxUtils tail seems better (-f works, but --pid seems not to, -n but not --lines=n fails with -f), but appears to be a dead project.

  • Cygwin is a big ugly mush, could perhaps just use the DLL and coreutils package - but still has problems like --pid not working with native win32 processes.

彻夜缠绵 2024-07-26 09:16:06

如果您根本不想安装任何东西,您可以“构建您自己的”批处理文件,该文件通过标准 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

If you do not want to install anything at all you can "build your own" batch file that does the job from standard Windows commands. Here are some pointers as to how to do it.

1) Using find /c /v "" yourinput.file, get the number of lines in your input file. The output is something like:

---------- T.TXT: 15

2) Using for /f, parse this output to get the number 15.

3) Using set /a, calculate the number of head lines that needs to be skipped

4) Using for /f "skip=n" skip the head lines and echo/process the tail lines.

If I find the time, I will build such a batch file and post it back here.

EDIT: 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
四叶草在未来唯美盛开 2024-07-26 09:16:06

通过 Windows PowerShell,您可以使用:

Get-Content <file> -Wait

With Windows PowerShell you can use:

Get-Content <file> -Wait
爱你不解释 2024-07-26 09:16:06

我使用过Tail For Windows。 当然不如使用那么优雅

tail

but then, you're using Windows. ;)

I've used Tail For Windows. Certainly not as elegant as using

tail

but then, you're using Windows. ;)

清欢 2024-07-26 09:16:06

我在这里的答案中没有看到 Log Expert。

它是可定制的并且非常适合处理日志文件。 到目前为止,它是我认为最好的 Windows 图形日志查看器。

不幸的是,该软件不再可用。 您可以在 archive.org

I haven't seen Log Expert anywhere among answers here.

It's customizable and is quite good for going around log files. So far it's the best Windows graphical log viewer for me.

Unfortunately, this software is no longer available. You can read about it on archive.org.

祁梦 2024-07-26 09:16:06

我最近使用过Mtail,看起来效果很好。 这就是像上面提到的baretail那样的GUI类型。
输入图像描述这里

I've used Mtail recently and it seems to work well. This is the GUI type like baretail mentioned above.
enter image description here

提笔落墨 2024-07-26 09:16:06

Download the tail command, part of Windows Server 2003 Resource Kit Tools from Microsoft itself.

浅笑依然 2024-07-26 09:16:06

尝试UNIX 的 Windows 服务。 提供shell、awk、sed等以及tail。

更新 -:不幸的是,截至 2019 年,该系统不再在 Microsoft 下载中心提供。

Try Windows Services for UNIX. Provides shells, awk, sed, etc. as well as tail.

Update -: Unfortunately, as of 2019 this system is no longer available on the Microsoft Download Center.

霞映澄塘 2024-07-26 09:16:06

我更喜欢 TailMe,因为可以在一个窗口中同时观看多个日志文件: http:// /www.dschensky.de/Software/Staff/tailme_en.htm

I prefer TailMe because of the possibility to watch several log files simultaneously in one window: http://www.dschensky.de/Software/Staff/tailme_en.htm

森末i 2024-07-26 09:16:06

DOS没有尾部命令; 您可以在此处下载 GNU tail 和其他 GNU 工具的 Windows 二进制文件。

DOS has no tail command; you can download a Windows binary for GNU tail and other GNU tools here.

妄想挽回 2024-07-26 09:16:06

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

Another option would be to install MSYS (which is more leightweight than Cygwin).

请帮我爱他 2024-07-26 09:16:06

DOS 的 type 的工作方式类似于 *nux 的 cat,尽管就像 cat 一样,它确实转储整个文件,因此它并不是真正的 tail,但在紧要关头无需下载/安装真正的 tail 替代品即可使用。

DOS's type works like *nux's cat, though just like cat, it does dump the whole file, so it's not really a true tail, but it's going to be available in a pinch without downloading/installing a true tail substitute.

暖树树初阳… 2024-07-26 09:16:06

我刚刚写了这个小批处理脚本。 它不像 Unix“tail”那么复杂,但希望有人可以添加它以改进它,例如将输出限制为文件的最后 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

I just wrote this little batch script. It isn't as sophisticated as the Unix "tail", but hopefully someone can add on to it to improve it, like limiting the output to the last 10 lines of the file, etc. If you do improve this script, please send it to me at robbing ~[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
甜嗑 2024-07-26 09:16:06

tail 命令和许多其他命令可以在 Windows 资源工具包工具 包。

The tail command and many others are available in the Windows Resource Kit Tools package.

吾家有女初长成 2024-07-26 09:16:06

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

比 Cygwin 重量更轻,更便携。

If you want to use Win32 ports of some Unix utilities (rather than installing Cygwin), I recommend GNU utilities for Win32.

Lighter weight than Cygwin and more portable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文