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 come to mind when I 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 my 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, >>.

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

ipconfig /all > mynetworksettings.txt

In this example, I save all the network configuration information that I'd usually see on screen after running ipconfig /all, to a file by the name of mynetworksettings.txt.

As you can see, the > redirection operator goes between the ipconfig command and the name of the file I 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 output the command's results to a file in a specific folder that doesn't yet exist, first create the folder and the run the command.

ping > "C:\Users\Tim\Desktop\Ping Results.txt"

Here, I execute the ping command and output the results to a file by the name of Ping Results.txt located on my desktop, which is at C:\Users\Tim\Desktop. I wrapped the entire file path in quotes because there was a space involved.

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

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.

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.

If you're still confused about command redirection, check out my Get More Help page for information about contacting me on social networks or via email, posting on tech support forums, and more. I'd be happy to answer any questions you have.