Windows read file cmd windows

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.

Peter Mortensen's user avatar

asked Jun 20, 2013 at 15:16

Refael's user avatar

2

We can use the ‘type’ command to see file contents in cmd.

Example —

type abc.txt

More information can be found HERE.

Peter Mortensen's user avatar

answered Dec 25, 2015 at 1:22

Anmol Saraf's user avatar

Anmol SarafAnmol Saraf

15.1k10 gold badges51 silver badges60 bronze badges

1

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.

Community's user avatar

answered Jun 20, 2013 at 15:24

inf3rno's user avatar

inf3rnoinf3rno

25k11 gold badges115 silver badges197 bronze badges

1

To show content of a file:

type file.txt — cmd

cat file.txt — bash/powershell

answered Apr 20, 2021 at 2:28

LaurentBaj's user avatar

LaurentBajLaurentBaj

4615 silver badges10 bronze badges

You can use the ‘more’ command to see the content of the file:

more filename.txt

Peter Mortensen's user avatar

answered Jun 5, 2017 at 19:12

H.Marroquin's user avatar

1

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"

Peter Mortensen's user avatar

answered Feb 17, 2016 at 12:59

Eyal's user avatar

EyalEyal

1611 silver badge9 bronze badges

1

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

answered May 18, 2016 at 18:50

Michael Yaeger's user avatar

1

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.

answered Jun 14, 2020 at 16:01

Anic17's user avatar

Anic17Anic17

7115 silver badges18 bronze badges

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.

Peter Mortensen's user avatar

answered Mar 11, 2017 at 3:08

Johnny G Gaming's user avatar

1

There is no built in option available with Windows. To constantly monitor logs you can use this free application BareTailPro.

Peter Mortensen's user avatar

answered Jun 20, 2013 at 15:21

Sudheej's user avatar

SudheejSudheej

1,8836 gold badges30 silver badges58 bronze badges

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.

Anic17's user avatar

Anic17

7115 silver badges18 bronze badges

answered Nov 19, 2019 at 18:25

user11116047's user avatar

0

You can use either more filename.[extension] or type filename.[extension]

enter image description here

StupidWolf's user avatar

StupidWolf

45.2k17 gold badges40 silver badges72 bronze badges

answered Jun 4, 2021 at 6:12

Mohammed Siraj B's user avatar

2

tail -3 d:\text_file.txt

tail -1 d:\text_file.txt

I assume this was added to Windows cmd.exe at some point.

Ian's user avatar

Ian

30.3k19 gold badges70 silver badges107 bronze badges

answered Jan 29, 2016 at 14:14

noni's user avatar

2

on January 1, 2009

We can read a text file from command line using type command. This command is similar to cat command on Linux.

Example: Let us print the contents of the file c:\boot.ini

C:\>type c:\boot.ini
[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(2)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Microsoft Windows XP Home Edition"

If the file is very huge, we can use more command to read the data one page at a time. This more command is pretty much similar to the Linux more command.

Syntax of the command is:

more filename

This command prints one page text on the console and waits for the user to press Enter before it shows the next page.

The above explained commands work in Windows 7, Windows 10 and all Server editions

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.

Peter Mortensen's user avatar

asked Jun 20, 2013 at 15:16

Refael's user avatar

2

We can use the ‘type’ command to see file contents in cmd.

Example —

type abc.txt

More information can be found HERE.

Peter Mortensen's user avatar

answered Dec 25, 2015 at 1:22

Anmol Saraf's user avatar

Anmol SarafAnmol Saraf

15.1k10 gold badges51 silver badges60 bronze badges

1

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.

Community's user avatar

answered Jun 20, 2013 at 15:24

inf3rno's user avatar

inf3rnoinf3rno

25k11 gold badges115 silver badges197 bronze badges

1

To show content of a file:

type file.txt — cmd

cat file.txt — bash/powershell

answered Apr 20, 2021 at 2:28

LaurentBaj's user avatar

LaurentBajLaurentBaj

4615 silver badges10 bronze badges

You can use the ‘more’ command to see the content of the file:

more filename.txt

Peter Mortensen's user avatar

answered Jun 5, 2017 at 19:12

H.Marroquin's user avatar

1

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"

Peter Mortensen's user avatar

answered Feb 17, 2016 at 12:59

Eyal's user avatar

EyalEyal

1611 silver badge9 bronze badges

1

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

answered May 18, 2016 at 18:50

Michael Yaeger's user avatar

1

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.

answered Jun 14, 2020 at 16:01

Anic17's user avatar

Anic17Anic17

7115 silver badges18 bronze badges

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.

Peter Mortensen's user avatar

answered Mar 11, 2017 at 3:08

Johnny G Gaming's user avatar

1

There is no built in option available with Windows. To constantly monitor logs you can use this free application BareTailPro.

Peter Mortensen's user avatar

answered Jun 20, 2013 at 15:21

Sudheej's user avatar

SudheejSudheej

1,8836 gold badges30 silver badges58 bronze badges

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.

Anic17's user avatar

Anic17

7115 silver badges18 bronze badges

answered Nov 19, 2019 at 18:25

user11116047's user avatar

0

You can use either more filename.[extension] or type filename.[extension]

enter image description here

StupidWolf's user avatar

StupidWolf

45.2k17 gold badges40 silver badges72 bronze badges

answered Jun 4, 2021 at 6:12

Mohammed Siraj B's user avatar

2

tail -3 d:\text_file.txt

tail -1 d:\text_file.txt

I assume this was added to Windows cmd.exe at some point.

Ian's user avatar

Ian

30.3k19 gold badges70 silver badges107 bronze badges

answered Jan 29, 2016 at 14:14

noni's user avatar

2

If you want to read a file using the Windows CMD command and print it on the console, you can make use of the type command,

Type: Displays the contents of a text file or files.

Syntax: TYPE [drive:][path] filename

Example:

C:\>type d:\countries.txt
China
USA
France
Poland
Sweden
Japan
Australia
C:\>

If the file is too huge then type command will keep on buffering the text on the console, in such a case you can make use of more command,

C:\>more d:\countries.txt
China
USA
France
Poland
Sweden
Japan
Australia
India
Nepal
Bhutan
Sri Lanka
Germany
Canada
-- More (78%) --

More command Windows CMD

More command Windows CMD

C:\>help more
Displays output one screen at a time.

MORE [/E [/C] [/P] [/S] [/Tn] [+n]] < [drive:][path]filename
command-name | MORE [/E [/C] [/P] [/S] [/Tn] [+n]]
MORE /E [/C] [/P] [/S] [/Tn] [+n] [files]

    [drive:][path]filename  Specifies a file to display one
                            the screen at a time.

    command-name            Specifies a command whose output
                            will be displayed.

    /E      Enable extended features
    /C      Clear screen before displaying page
    /P      Expand FormFeed characters
    /S      Squeeze multiple blank lines into a single line
    /Tn     Expand tabs to n spaces (default 8)

            Switches can be present in the MORE environment
            variable.

    +n      Start displaying the first file at line n

    files   List of files to be displayed. Files in the list
            are separated by blanks.

    If extended features are enabled, the following commands
    are accepted at the -- More -- prompt:

    P n     Display next n lines
    S n     Skip next n lines
    F       Display next file
    Q       Quit
    =       Show line number
    ?       Show help line
    <space> Display next page
    <ret>   Display next line

This article lists down various commands that you can use to manage files and folders through Command-Line in Windows 11/10. Although a lot of users prefer using a graphical user interface to manage files for a hassle-free experience, some also use the command-line interface to perform file management tasks. In any case, it is always better to know alternative solutions to execute a task.

In this guide, I will be creating a list of useful commands that you can use for file or folder management on your Windows 10 PC. To perform a specific task on files or folders, there is a dedicated command that you need to enter in CMD. Let’s check out these commands!

Useful Commands to Manage Files and Folders through CMD in Windows 10

Here are the commands that you should know to manage files and folders using Command Prompt in Windows 11/10:

1] Create a File or Folder in CMD

To create a folder, type the folder name with the location where you want to create the folder. Here is the command:

mkdir <folder name with path>

For example;

mkdir C:\Users\KOMAL\Documents\TWC

To create a file of a specific size (in bytes), use the below command:

fsutil file createnew file.txt 4000

In place of file.txt, enter the filename with its extension and full path. And, 4000 is the file size in bytes.

Related: How to Create Multiple Folders using Command Prompt and PowerShell.

2] Delete Files or Folder in CMD

You can remove a folder using the below command:

rmdir <folder name with path>

In order to delete a file, the command is:

del "<filename with path>"

If you want to delete all files from the current folder, enter the command:

del *

To delete files with a specific extension only, say png, use the command:

del *.png

If you want to delete files with a particular string in their filename, e.g., xyz, you can use the below command:

del *xyz*

3] Find Files in a Particular Folder

To find files inside a folder based on different parameters, you first need to navigate to the folder using the command:

cd "<folder name with location>"

Now, you can find files older than n days in a specific folder using the below command:

forfiles /s /m *.* /d -n /c "cmd /c echo @file

Replace -n with the number of days. Like if you want to find files older than 2 days, type -2.

To find files larger than a specific size, use the command:

forfiles /S /M * /C "cmd /c if @fsize GEQ 3741824 echo @path"

In the above command, 3741824 is the file size to search files greater than this size.

Read: Managing Files and Folders in Windows 11 – Tips & Tricks

4] Rename all file extensions present in a folder at once

You can also batch rename file extensions in CMD. Suppose, you want to rename the file extension of all images to JPG, you can use the below command:

ren *.* *.jpg

5] Get File Creation Time and Date

To check the creation time and date of a specific file, use the command:

dir /T:C filename

6] Check for a string inside a file

To find all lines containing a particular string in a file, you can use the command:

findstr string file-name

For example, to display all lines with “twc” in a text file, you need to enter the command:

findstr twc twc.txt

Do remember that the above command is case-sensitive.

To find sentences with any specified string, use a command like:

findstr /C:"string1 string2 string3..." filename

7] Check for all Hidden Files in a Folder

Use the below command to get a list of hidden files in a directory:

dir /A:H /B

8] Compress a File in CMD

The command to compress a file in a folder is:

compact /c filename

9] Hide/ Unhide a file through CMD

To hide a file, the command used is:

attrib + h filename

You can unhide the file again using the command:

attrib -h filename

10] Set/ Unset Read-Only attribute to a file

To make a file read-only, the command is:

attrib +R filename

If you want to remove the read-only attribute from a file, the command is:

attrib -R filename

11] Command to Rename a File/Folder

rename oldfilename.pdf newfilename.pdf

12] Read File Content in CMD

You can read text file content in CMD using the below command:

more filename

13] Open a File in Default Application

You can open a file in its default application by entering a simple command:

"filename-with-path"

14] Move File / Folder to different Location

Suppose you want to move TWC12.pdf file to TWC folder in G drive, use below command:

move TWC12.pdf G:\TWC\

Command to move all files with a specific extension:

move *.png G:\TWC\

To move files starting with a particular letter, say A, command is:

move A* G:\TWC\

Similarly, you can move a folder using a command like below:

move foldername <new location>

For example:

move TWC1 G:\TWC\

15] Command to Copy Files

You can copy files from one location to another using command:

copy Sourcefolder DestinationFolder

Hope this article helps you learn some useful commands to manage files and folders through the command line in Windows 11/10.

  • Windows recovery в биосе что это
  • Windows rdp не работает буфер обмена windows
  • Windows recovery environment что это такое
  • Windows rdp update windows 7
  • Windows recovery environment как убрать