I want to display the content of a text file in a CMD window. In addition, I want to see the new lines that added to file, like tail -f
command in Unix.
问题:
回答1:
You can use the more
command. For example:
more filename.txt
Take a look at GNU utilities for Win32 or download it:
回答2:
We can use the 'type' command to see file contents in cmd.
Example -
type abc.txt
More information can be found HERE.
回答3:
I don't think there is a built-in function for that
xxxx.txt > con
This opens the files in the default text editor in windows...
type xxxx.txt
This displays the file in the current window. Maybe this has params you can use...
There is a similar question here: CMD.EXE batch script to display last 10 lines from a txt file So there is a "more" command to display a file from the given line, or you can use the GNU Utilities for Win32 what bryanph suggested in his link.
回答4:
Using a single PowerShell command to retrieve the file ending:
powershell -nologo "& "Get-Content -Wait c:\logFile.log -Tail 10"
It applies to PowerShell 3.0 and newer.
Another option is to create a file called TAIL.CMD with this code:
powershell -nologo "& "Get-Content -Wait %1 -Tail %2"
回答5:
To do this, you can use Microsoft's more advanced command-line shell called "Windows PowerShell." It should come standard on the latest versions of Windows, but you can download it from Microsoft if you don't already have it installed.
To get the last five lines in the text file simply read the file using Get-Content
, then have Select-Object
pick out the last five items/lines for you:
Get-Content c:\scripts\test.txt | Select-Object -last 5
Source: Using the Get-Content Cmdlet
回答6:
You can use the 'more' command to see the content of the file:
more filename.txt
回答7:
There is no built in option available with Windows. To constantly monitor logs you can use this free application BareTailPro.
回答8:
You can get the TAIL utility from the Windows Server 2003 Resource Kit Tools.
Here are additional details -- Tail command for Windows (CMD).
回答9:
If you want it to display the content of the file live, and update when the file is altered, just use this script:
@echo off
:start
cls
type myfile.txt
goto start
That will repeat forever until you close the cmd window.
回答10:
tail -3 d:\text_file.txt
tail -1 d:\text_file.txt
I assume this was added to Windows cmd.exe at some point.