How to send command line output to text file on Windows
On Home windows 11, 10, 8, 7, and even older variations, it’s attainable to avoid wasting a command’s output, and on this information, I’ll clarify tips on how to full this course of. Normally, you open the Command Immediate or PowerShell, run one or a sequence of instructions, then choose and duplicate the output, create a textual content file, paste the outcomes, and save the file. Though this can be a widespread method, it takes plenty of steps. You may as well take a screenshot or image together with your cellphone, however these will not be the perfect methods to perform this process.
The proper method is to append the command syntax you wish to run with the right command that Command Immediate and PowerShell supply to avoid wasting the output to a textual content file.
On this information, I’ll clarify the completely different strategies to avoid wasting the command output to a textual content file on nearly any model of Home windows.
Save command output to a textual content file on Home windows
On Home windows, you possibly can export the command output with completely different instructions relying on whether or not you employ Command Immediate or PowerShell.
From Command Immediate
To save lots of the output of a command from Command Immediate, use these steps:
-
Open Begin.
-
Seek for Command Immediate, right-click the highest consequence, and select the Run as administrator choice.
-
(Choice 1) Kind the next command to export the command output to a textual content file and press Enter:
Command-syntax > C:PathtoExport-results.txt
Within the command, change “Command-syntax” with the command syntax and specify the trail and the identify of the textual content file to avoid wasting the contents. For instance,
ipconfig > C:Export-results.txt
-
(Choice 2) Kind the next command to export the command and append the consequence to an current textual content file, and press Enter:
Command-syntax >> C:PathtoExport-results.txt
-
(Choice 3) Kind the next command to seize and consider the output within the console and press Enter:
Command-syntax > C:PathtoExport-results.txt | sort C:PathtoExport-results.txt
The greater-than >
redirect operator makes it attainable to redirect regardless of the consequence of the command is right into a textual content. You’re not restricted to textual content recordsdata. You may as well export to “.doc,” “.xls,” and different codecs.
If it is advisable to create an inventory of all of the recordsdata and folders from a particular location, as a substitute of typing one after the other, use this command:
Dir /b > C:Output-file.csv
If it is advisable to create an inventory of particular varieties of recordsdata, use this command:
Dir *.doc/b > C:Output-file.csv
The asterisk (*) represents any identify, the sort of file that you really want an inventory from, and (/b) makes use of naked format (no heading info or abstract).
From PowerShell
To save lots of the command output to a textual content file from PowerShell, use these steps:
-
Open Begin.
-
Seek for PowerShell, right-click the highest consequence, and select the Run as administrator choice.
-
(Choice 1) Kind the next command to export the command output to a textual content file and press Enter:
Command-syntax | tee C:PathtoExport-results.txt
Within the command, change “Command-syntax” with the command syntax and specify the trail and the identify of the textual content file to avoid wasting the contents. For instance,
ipconfig | tee C:Export-results.txt
-
(Choice 2) Kind the next command to seize and append the consequence to the top of a file and press Enter:
Command-syntax | tee -append C:PathtoExport-results.txt
The pipeline operator |
and tee
instructions (quick for “Tee-Object”) ship the seize of the output to the file whereas displaying the consequence on the console display screen. Additionally, the -append
choice prevents overriding an current file by appending the subsequent output to the top of the file.