When you type a command on the Windows command line, the output from the command is displayed in the command prompt window. For some commands, the output can be several rows long and sometimes longer than the height of the command window, causing you to scroll to view all of the output.
If you want to avoid this, or if you want to save a copy of the output generated by a command, you can copy the text from the command window and paste it into a text file. However, there is an easier method of “copying” output to a text file. You use the redirection command.
Redirect Command Line Output
To use the redirection command, use the “>” symbol and a filename at the end of the command you want to execute.
For example, if you want to save the output from the ipconfig command (displays networking settings), open the command window and type the following command.
ipconfig /all > network_info.txt
NOTE: This creates the file, network_info.txt, in the current directory. In this example, shown in the following image, the file will be saved to the C:\network_info directory. If you want to save the file to a different directory you can specify the full path of the directory in the command window as follows:
ipconfig /all > c:\my_directory\network_info.txt
Once you enter the command and press Enter, you are returned to the command prompt. The output is sent to the text file, but not to the screen, so you do not see the output.
The network_info.txt file is created in the current directory. To view the output, type the following command to open the text file in Notepad:
NOTE: If you saved the file to a different directory, be sure to put the full path to the file after “notepad.exe” on the command line as follows:
Note that you can also just browse to that directory in Explorer and open the file from there. Here is an example of the output if the ipconfig command in a text file.
To close Notepad, select Exit from the File menu.
To close the command window, type exit at the command prompt and press Enter.
NOTE: If you use the same filename a second time, that file will be overwritten and any output it previously contained will be lost. To preserve your previous output, use a different filename or you can append the output to the end of an existing file. To append data to an existing file, use two redirection symbols as shown below:
dir c:\my_music >> network_info.txt
NOTE: Redirection is also useful for saving directory listings. The previous command saves a listing of the c:\my_music directory into the end of the network_info.txt file. Enjoy!