Software & Apps > Windows 171 171 people found this article helpful How to Redirect Command Output to a File Use redirection operators to save a command's results to a file By Tim Fisher Tim Fisher Facebook Twitter Senior Vice President & Group General Manager, Tech & Sustainability Emporia State University Tim Fisher has more than 30 years' of professional technology experience. He's been writing about tech for more than two decades and serves as the SVP and General Manager of Lifewire. lifewire's editorial guidelines Updated on November 4, 2022 Reviewed by Jerrick Leger Reviewed by Jerrick Leger Jerrick Leger is a CompTIA-certified IT Specialist with more than 10 years' experience in technical support and IT fields. He is also a systems administrator for an IT firm in Texas serving small businesses. lifewire's editorial guidelines Tweet Share Email Tweet Share Email Windows The Ultimate Laptop Buying Guide What to Know The > redirection operator goes between the command and the file name, like ipconfig > output.txt.If the file already exists, it'll be overwritten. If it doesn't, it will be created.The >> operator appends the file. Instead of overwriting the file, it appends the command output to the end of it. Use a redirection operator to redirect the output of a command to a file. All the information displayed in Command Prompt after running a command can be saved to a file, which you can reference later or manipulate however you like. How to Use Redirection Operators While there are several redirection operators, 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 > networksettings.txt In this example, all the information normally seen on screen after running ipconfig /all, is saved to a file by the name of networksettings.txt. It's stored in the folder to the left of the command, the root of the D: drive in this case. The > redirection operator goes between the command and the filename. If the file already exists, it'll be overwritten. If it doesn't already exist, it will be created. Although 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 then run the command. Make folders without leaving Command Prompt with the mkdir command. ping 192.168.86.1 > "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, at C:\Users\jonfi\Desktop. The entire file path in wrapped in quotes because 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. The Append Redirection Operator The double-arrow operator appends, rather than replaces, a 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. Here's an example of what this LOG file might look like after a command has been exported to it: The >> redirection operator is useful when you're collecting similar information from different computers or commands, and you'd like all that data in a single file. The above redirection operator examples are within the context of Command Prompt, but you can also use them in a BAT file. When you use a BAT file to pipe a command's output to a text file, the exact same commands described above are used, but instead of pressing Enter to run them, you just have to open the .BAT file. Use Redirection Operators in Batch Files Redirection operators work in batch files by including the command just as you would from the Command Prompt: tracert yahoo.com > C:\yahootracert.txt The above is an example of how to make a batch file that uses a redirection operator with the tracert command. The yahootracert.txt file (shown above) will be created on the C: drive several seconds after executing the sample.bat file. Like the other examples above, the file shows everything Command Prompt would have revealed if the redirection operator wasn't used. Export Text Results in Terminal Terminal provides an easy way to create a text file containing the contents of whatever you see in Command Prompt. Although the same redirection operator described above works in Terminal, too, this method is useful for when you didn't use it. Here's how to export the results from a Terminal window: Right-click the tab you're working in and select Export Text. You can then choose where to save the TXT file. Was this page helpful? Thanks for letting us know! Get the Latest Tech News Delivered Every Day Subscribe Tell us why! Other Not enough details Hard to understand Submit