Redirect CMD command output to a file, with an example?
Use redirection operators to redirect or save the results of a command prompt in a file!
As with MAC OS and Linux, the solution is very simple also under all Microsoft Windows and server systems to redirect a CMD command output to a file, here is a simple example that administrators like when remote accessing the web server 2019, 2016, 2012, ... is used!
How to use redirection operators! The easiest way to learn how to use these redirection operators is to see a few examples!
Content / example / tips:
1.) Example 1 directory structure!
C: Windows>tree C:\ > d:\directory_structure_of_c.txt
In this example, stores the directory structure all the folders and subfolders that tree normally after running are all displayed on the screen, in a file named directory_structure_of_c.txt
As you can see, the ">" redirect operator goes between the tree command and the name of the file that is used here. Attention! If the file already exists, it will be overwritten. If it doesn't already exist, it will be created.
Although a file is created if it doesn't already exist, folders are not created. To output the results of the command to a file in a specific folder that does not yet exist, first create the folder and run the command.
2.) Example 2 List all Windows accounts!
C: Windows>net user > d:\user_on_PC.txt
In this example, a list of all Windows accounts that are normally displayed on the screen after running net user is saved in a file with the name user_on_PC.txt
3.) What is the advantage of redirection in a file and alternatives?
In the case of very long console returns (output text), these cannot be edited or viewed on the screen, especially if it is a few megabits of data, only a program such as ColorConsole can help, which is designed for up to 50 megabits.
A little hint:
In contrast to the standard CMD.EXE, the ColorConsole has full copy paste support. This means that complete output texts or only partial areas can be copied directly. Yes, even with the complete color syntax.
In short, there is enormous time-saving potential in this oh so small and inconspicuous program.
| (Image-1) Alternative CMD prompt as command output example!
4.) Example 3 Batch file with several commands in a text file!
If you don't want to use an alternative CMD for Windows, you can use the following example:
Two commands in a text file
Test.bat after issue.txt
The batch file
| (Image-2) Batch file with several commands in a text file!
5.) Example 4: For Windows 10 and MS Server 2019 Ctrl + A Ctrl + C!
Commands then use Ctrl + A to select everything and copy them to the clipboard with Ctrl + C
| (Image-3) Copy CMD command output to clipboard!
FAQ 41: Updated on: 30 July 2020 09:29
Please use Eraser to delete sensitive data. It can also clean digital SD memory cards of all recoverable data As with Linux, Appels Mac OS and other systems
It is very easy to create multiple guest accounts for guest users under Windows 10 / 8.1 / 7, or Windows Server by using command lines It is not only possible
The fastest way to run or start the command prompt in every Windows System, is via RUN-Dialog in Windows. Please start via Keyboard-Shortcut [Windows-Logo+R]
Find Your IP Address Quickly in every Windows OS, the solution is to simple for every User Account Please start the command Prompt cmd.exe and use the
The solution is simple to Delete and Overwrite files and folder permanently in every Windows OS at XP Please feel free and use cipher for this cipher
The solution to scan all protected system files and replaces incorrect versions with correct Microsoft versions in all Windows Systems. If you want scan
»» My question is not there in the FAQ
|Asked questions on this answer:|
- Is there a solution or possibility at the end of the script to copy or save the contents of the CMD window to a text file?
- I want to redirect output of two or more commands to an output.txt file from the command prompt?
- How can I redirect all output from a batch file?
- I have a batch script with multiple routines, now do I want to detailed a log file instead of just output in the CMD?
- Is there an option with little effort to save several lines from a script into a file or to copy the complete command prompt output, i.e. the text buffer content?
Keywords: windows, console, redirect, command, output, file, with, example, redirection, operators, save, results, prompt, linux, solution, very, simple, also, under, Questions, Answers, Software