HomeWINDOWSHow to view Text file in Command Prompt and PowerShell

How to view Text file in Command Prompt and PowerShell


If you want to view a Text file in Command Prompt window or PowerShell window in your Windows 11/10 system, then this tutorial will help you. You can view the entire text file or partial content using different commands. Though the first option that comes to mind for opening a TXT file in Windows 11/10 OS is perhaps Notepad, there are of course many other suitable options. For example, you can use free text editor tools (like Notepad++), a web browser, etc., to open and read a text file. Command Prompt and Windows PowerShell are also simple and built-in options covered in this post for this purpose.

view text file in command prompt and PowerShell Windows

We have already seen how to open a file or folder using Command Prompt or PowerShell. Now let’s check how we can read the content of a text file using these two utilities separately. We will start with Command Prompt first.

How to view a Text file in Command Prompt in Windows 11/10

view text file in cmd

To view a text file in Command Prompt in Windows 11/10, first type cmd in the Search box and hit the Enter key. Now in the Command Prompt window, use the Type command, provide the path of your TXT file along with the file name and file extension, and execute the command. Or else, you can open Command Prompt in a folder where your text is stored and then run the command. It would be like this:

Type TheWindowsClub.txt

Replace TheWindowsClub.txt with the actual text file stored on your computer. This will load all the content of that text file and show it in the CMD window.

If the text file is too large, then you can use the More command to view the text file with one screen at a time. The command would be:

More abc.txt

Again, replace abc.txt with the actual file. Once the command is executed, you will see a part of your text file (say 26%, 52%, etc.). After this, you can continue using the More command with other subcommands or keys such as:

  • Enter: Use this subcommand to display the next lines (one at a time) of your text file. You need to keep pressing the Enter key one by one
  • Spacebar: It displays the next screen or content of your text file that can fit the visible part of the CMD window
  • P <n>: To show the next N lines. You first need to press the P key and then provide a number say 9 and use the Enter key to display the next 9 lines of your file
  • S <n>: to skip the next N lines
  • Equal (=) to display the line number
  • Q to quit the More command, etc.

Related: Complete list of Command Prompt commands

View a Text file in PowerShell in Windows 11/10

Like Command Prompt, you can also view a text file using PowerShell in Windows 11/10 with a simple command. First, type powershell in the Search box and press the Enter key. Now use the Get-Content command and provide your text file along with its full path, file name, and file extension. The command would be:

Get-Content abc.txt

read text file using powershell

Replace abc with the actual file name and this will display the entire content of the text file in the PowerShell window.

Now you can also use a variable instead of the entire command, again and again, that can help you read the partial content of a text file, read the first 15 lines, etc. For this, move all the content to a variable using the following command:

$file_data = Get-Content TextFile.txt

use variable for text file in powershell

Replace TextFile with the actual file name.

Now you can use this $file_data variable for further actions. For example, if you want to view a specific line, say 10, of your text file, then execute the following command:


Similarly, to read the first N number of lines (say first 15 lines) of the TXT file, use the variable with a pipe. The command is:

$file_data | Select-Object -First 15

In a similar way, for reading the last N lines (say 20) of your text file, use this command:

$file_data | Select-Object -Last 20

Once you close Windows PowerShell and launch it again, you can move the content again in the variable and then use it.

That’s it.

How do I open a text file as an administrator in Windows 11?

To open a text file as administrator on your Windows 11/10 computer, you actually need to run the associated program with administrative privileges. For that, right-click on the program shortcut or executable file, select the Run as administrator option, and then open a text file in that program. Or else, you can make a program always run as administrator in Windows 11/10 to skip the hassle. Access the Properties window of your program, switch to the Compatibility tab, and select Run this program as an administrator option.

How do I preview files in Windows 11?

You can show or turn on the Preview pane of File Explorer in Windows 11/10 and then select a text file or an image file to preview it. The Preview pane can also be expanded easily. On the other hand, if you want to preview a video file (say MP4), or a document like DOCX, PDF, etc., then you can use some free tools like QuickLook, Seer, One Commander, etc., that let you preview files without opening them.

Read next: How to search for files using Command Prompt in Windows.

view text file in command prompt and PowerShell Windows

Source link



Please enter your comment!
Please enter your name here