How to Redirect Command Output to a File

Use Redirection Operators to Save a Command's Results to a File

Screenshot showing how to redirect the ipconfig command results to a text file
Redirecting Command Prompt Results to a File.

Many Command Prompt commands, and DOS commands for that matter, are executed not just to do something, but to provide you with information.

The ping command, dir command, tracert command, and several others might come to mind when you think of popular commands that produce a lot of data in the Command Prompt window.

Unfortunately, three hundred lines of information from the dir command doesn't do you much good as it rushes by. Yes, the more command can be helpful here, but what if you want to look at the output later, or send it to a tech support group, or use it in a spreadsheet, etc.?

This is where a redirection operator becomes very useful. Using a redirection operator, you can redirect the output of a command to a file. It's one of our favorite Command Prompt Tricks & Hacks.

In other words, all the information that's displayed in the Command Prompt after running a command can instead be saved to a file which you can open in Windows to reference later or manipulate however you like.

While there are several redirection operators, which you can read in detail about here, two, in particular, are used to output the results of a command to a file: the greater-than sign, >, and the double greater-than sign, >>.

How to Use Redirection Operators

The easiest way to learn how to use these redirection operators is to see some examples:

Screenshot showing how to redirect the ipconfig command results to a text file
Redirecting 'ipconfig' Results to a TXT File.
ipconfig /all > mynetworksettings.txt

In this example, all the network configuration information normally seen on screen after running ipconfig /all, is saved to a file by the name of mynetworksettings.txt. It's stored in the folder to the left of the command, C:\Users\jonfi in this case.

As you can see, the > redirection operator goes between the ipconfig command and the name of the file you want to store the information in. If the file already exists, it'll be overwritten. If it doesn't already exist, it will be created.

Note: Though a file will be created if doesn't already exist, folders will not. To save the command output to a file in a specific folder that doesn't yet exist, first create the folder and the run the command. You can make folders without leaving Command Prompt with the mkdir command.

Screenshot showing how to redirect the ping command results to a text file in a different folder
Redirecting "ping" Results to a TXT File in a Different Folder.
ping 10.1.0.12 > "C:\Users\jonfi\Desktop\Ping Results.txt"

Here, when the ping command is executed, Command Prompt outputs the results to a file by the name of Ping Results.txt located on the jonfi user's desktop, which is at C:\Users\jonfi\Desktop. The entire file path in wrapped in quotes because there was a space involved.

Remember, when using the > redirection operator, the file specified is created if it doesn't already exist and is overwritten if it does exist.

Screenshot showing how to use Command Prompt to append ipconfig results to an existing file
Appending "ipconfig" Results to an Existing LOG File.
ipconfig /all >> \\server\files\officenetsettings.log

This example uses the >> redirection operator which functions in much the same way as the > operator, only instead of overwriting the output file if it exists, it appends the command output to the end of the file.

So, let's say the first time you use this command is on Computer A. The officenetsettings.log file is created and the result of ipconfig /all on Computer A is written to the file. Next you run the same command on Computer B. This time, however, the result is added to the officenetsettings.log so the network information from both Computer A and Computer B are included in the file.

Here's an example of what this LOG file might look like after a command has been exported to it:

Screenshot of a LOG file with commands written to it
A LOG File of Command Prompt Results.

As you might have already realized, the >> redirection operator is really useful when you're collecting similar information from multiple computers or commands and you'd like all of that data in a single file.