Auto save the output of any cmd in a text file - in Windows

Auto save the output of any cmd in a text file - in Windows
- 20th Mar, 2020 | 2min read

It's important sometimes to save the output of any command we use and windowsOS provides a way to do so

when using any command in a terminal, you just have to add > plus the file name (along with its path if any) in which you want to save the output, like

dir > myTextFile.txt

In above we are using dir as a command that will list all files details inside the current directory. Now you can open the file you provided, in above case (myTextFile.txt), you will see the output of the command you used in it

- If the file you mentioned is not their then it will automatically create one.

Well the above command overwrites the same when you re-run any command using the same file to save the output. Lets say

ipconfig > myTextFile.txt

In above we are using ipconfig as a command that will list ip configuration details related to your system. In this case, when you open the file myTextFile.txt, you will see only the result of ipconfig. since it overwrites the file

So what if you want to append or add the output in the same file.Well in that case you just have to change a little in the command, instead of > you have to run >> and you are good to go, like

help >> myTextFile.txt

In above we are using help as a command that will list all the basic command details that can be used on the system. Now you can open the file you provided, in above case (myTextFile.txt), you will see the output of the command written at the end

Conclusion

In this tutorial, we learned how to write the output of any command into a file

Well, Now you can use the output file anywhere, for any logical use you can think of. You can also use batch scripting for the advance use

HomeOld