Saving the output of a Windows Command Prompt command is a great way to get a nice neat copy to share with support staff, analyze longer outputs using your favorite text editor, or otherwise interact with the output with more flexibility than staying in the command window allows for.
To redirect the output of a command to a text file instead of printing it to the screen in the command window, we simply need to execute the command and append it with the “>” angle bracket symbol—called, appropriately enough, a redirection.
If, for example, you wanted to save the output of the DIR function to a text file instead of scrolling for page after page on your screen in the command window, you would execute the command
DIR > some-descriptive-filename.txt
like so, where we’ve run the DIR command from the C:\ directory and saved the output to the root directory of the D drive as “c-drive-directory-output.txt”.
Notice that the output is not displayed in the command window above, but when we open the text document, we see the full command output:
Any command that has a command window output (no matter how big or small) can be appended with
> filename.txt and the output will be saved to the specified text file.
In addition to executing the command as a one-off affair, you can also tweak the command slightly in order to dump sequential output to the same text file for your convenience. Let’s say, for example, you want to send the output of the same command to the same text file before and after you make some change (like, say, rebooting your router and acquiring a new IP address). You can first issue the command with a single angel bracket “>” and then repeat future instances of the same command with a double angle bracket “>>”.
In this way, the same filename.txt will be appended (instead of overwritten as it would be with a single bracket) with additional command outputs.