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
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: 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: 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 oneSpacebar: It displays the next screen or content of your text file that can fit the visible part of the CMD windowP
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:
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:
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: In a similar way, for reading the last N lines (say 20) of your text file, use this command: 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.