Command line tip #4 - How to save the output of a command to a file
Normally, the results of a command-line operation are displayed on the screen. However, a more permanent record can be created by sending the results to a new text file with the redirect symbol “>”. If the file already exists, any previous contents will be replaced. You can append results to the contents of an existing text file with the symbols “>>”. In a post some time ago, I discussed how to use the “dir” command and the redirect to list files of a certain type. As noted in that post, the command dir “C:\my folder\*.ext†/s /q > C:\list.txtwill list all files with the extension EXT that are in my folder and its subfolders and place the list in a text file list.txt that is created by the command.
Another example of possible use of a redirect is provided by the case of selective deleting discussed in tip #3. The command lists the files being deleted on the screen. Perhaps you would like a record of what was deleted. In that case, you can modify the delete command by adding a redirect to a file. For example:del /s /f /q C:\*.tmp > C:\templist.txt
The file to be used for the list can be located anywhere you want as long as you designate the full path. Any file or folder name with spaces will require that the path be enclosed in quotes as indicated in the example of my folder in the first command above.
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments
No comments yet.
Sorry, the comment form is closed at this time.