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.
14 Answers
You can use the more command. For example:
more filename.txt
Take a look at GNU utilities for Win32 or download it:
We can use the 'type' command to see file contents in cmd.
Example -
type abc.txt
More information can be found HERE.
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.
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
You can do that in some methods:
One is the type command: type filename
Another is the more command: more filename
With more you can also do that: type filename | more
The last option is using a for
for /f "usebackq delims=" %%A in (filename) do (echo.%%A)
This will go for each line and display it's content. This is an equivalent of the type command, but it's another method of reading the content.
If you are asking what to use, use the more command as it will make a pause.
There is no built in option available with Windows. To constantly monitor logs you can use this free application BareTailPro.
You can get the TAIL utility from the Windows Server 2003 Resource Kit Tools.
Here are additional details -- Tail command for Windows (CMD).
If you want to display for example all .config (or .ini) file name and file content into one doc for user reference (and by this I mean user not knowing shell command i.e. 95% of them), you can try this :
FORFILES /M *myFile.ini /C "cmd /c echo File name : @file >> %temp%\stdout.txt && type @path >> %temp%\stdout.txt && echo. >> %temp%\stdout.txt" | type %temp%\stdout.txt
Explanation :
- ForFiles : loop on a directory (and child, etc) each file meeting criteria
- able to return the current file name being process (@file)
- able to return the full path file being process (@path)
- Type : Output the file content
Ps : The last pipe command is pointing the %temp% file and output the aggregate content. If you wish to copy/paste in some documentation, just open the stdout.txt file in textpad.
