I want to tướng display the nội dung of a text tệp tin in a CMD window. In addition, I want to tướng see the new lines that added to tướng tệp tin, lượt thích tail -f
command in Unix.
asked Jun trăng tròn, 2013 at 15:16
RefaelRefael
7,27310 gold badges37 silver badges54 bronze badges
2
We can use the 'type' command to tướng see tệp tin contents in cmd.
Example -
type abc.txt
More information can be found HERE.
answered Dec 25, năm ngoái at 1:22
Anmol SarafAnmol Saraf
15.7k10 gold badges54 silver badges61 bronze badges
1
I don't think there is a built-in function for that
This displays the tệp tin in the current window (maybe this has params):
type xxxx.txt
This opens the files in the mặc định text editor in windows:
xxxx.txt > con
There is a similar question here. So there is a "more" command to tướng display a tệp tin from the given line, or you can use the GNU Utilities for Win32 what bryanph suggested in his links.
Xel
5712 gold badges8 silver badges28 bronze badges
answered Jun trăng tròn, 2013 at 15:24
inf3rnoinf3rno
26.1k12 gold badges119 silver badges205 bronze badges
1
To show nội dung of a file:
type tệp tin.txt
- cmd
cat tệp tin.txt
- bash/powershell
answered Apr trăng tròn, 2021 at 2:28
LaurentBajLaurentBaj
5386 silver badges13 bronze badges
You can use the 'more' command to tướng see the nội dung of the file:
more filename.txt
answered Jun 5, 2017 at 19:12
1
Using a single PowerShell command to tướng retrieve the tệp tin ending:
powershell -nologo "& "Get-Content -Wait c:\logFile.log -Tail 10"
It applies to tướng PowerShell 3.0 and newer.
Another option is to tướng create a tệp tin called TAIL.CMD with this code:
powershell -nologo "& "Get-Content -Wait %1 -Tail %2"
answered Feb 17, năm nhâm thìn at 12:59
EyalEyal
1611 silver badge9 bronze badges
1
To bởi 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 tải về it from Microsoft if you don't already have it installed.
To get the last five lines in the text tệp tin simply read the tệp tin 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
answered May 18, năm nhâm thìn at 18:50
1
You can bởi that in some methods:
One is the type
command: type filename
Another is the more
command: more filename
With more
you can also bởi that: type filename | more
The last option is using a for
for /f "usebackq delims=" %%A in (filename) bởi (echo.%%A)
This will go for each line and display it's nội dung. This is an equivalent of the type
command, but it's another method of reading the nội dung.
If you are asking what to tướng use, use the more
command as it will make a pause.
answered Jun 14, 2020 at 16:01
Anic17Anic17
8077 silver badges20 bronze badges
You can use either more filename.[extension] or type filename.[extension]
StupidWolf
46.8k17 gold badges49 silver badges81 bronze badges
answered Jun 4, 2021 at 6:12
2
If you want it to tướng display the nội dung of the tệp tin live, and update when the tệp tin 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.
answered Mar 11, 2017 at 3:08
1
There is no built in option available with Windows. To constantly monitor logs you can use this miễn phí application BareTailPro.
answered Jun trăng tròn, 2013 at 15:21
SudheejSudheej
2,0096 gold badges33 silver badges60 bronze badges
If you want to tướng display for example all .config
(or .ini
) tệp tin name and tệp tin nội dung 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 tệp tin meeting criteria
- able to tướng return the current tệp tin name being process (@file)
- able to tướng return the full path tệp tin being process (@path)
- Type : Output the tệp tin content
Ps : The last pipe command is pointing the %temp%
tệp tin and output the aggregate nội dung. If you wish to tướng copy/paste in some documentation, just open the stdout.txt tệp tin in textpad.
Anic17
8077 silver badges20 bronze badges
answered Nov 19, 2019 at 18:25
tail -3 d:\text_file.txt
tail -1 d:\text_file.txt
I assume this was added to tướng Windows cmd.exe at some point.
Ian
30.8k19 gold badges76 silver badges111 bronze badges
answered Jan 29, năm nhâm thìn at 14:14
2