DOS Command Line Stuff Worth Remembering

Author:
phil
Created:
Monday, July 26th, 2010
Last Updated:
Monday, November 29th, 2010

Disclaimer: Accessing the information on this page means you agree to the Sites Terms of Service


This is an ongoing collection of dos command line tips and tricks I've run across over the years. I tend to forget what I did 5 min ago, let alone a bunch of DOS commands, so I'm collecting the stuff I've found here as a place of reference. Much of what you will find here is probably posted on the internet somewhere (which is where I got it from) or, I've created a few little tricks myself to help me along the way.


Append to New File - This will create OR overwrite the existing file.

dos-program.exe > file.txt

Append to Existing File - This will create OR add to any existing file.

dos-program.exe >> file.txt

Script to add carriage returns to appended file
Note: the following script will overwrite the existing file each time it is run...

@echo off
echo Run the fancy program and output to file!
dos-program.exe > file.txt
echo. >> file.txt
echo. >> file.txt
dos-program2.exe >> file.txt

get Computer Name Environment Variable

echo %computername%

Environment Variable Heaven
http://en.wikipedia.org/wiki/Environment_variable

Execute DOS Command Scripts / Bat files from UNC Network path - This will automatically map the last available drive letter to the UNC path you currently reside in. Let's say you are in \\computer\folder\test This will automatically map Z:\ to the test folder for you.

@echo off
cls
pushd %~dp0
echo Do Something cool!
popd

Append the Current Time to a File

net time \\%computername% |find "time" > "file.txt"

This will output in the following format:
Current time at \\THISCOMPUTER is 7/26/2010 10:28 AM

Post Comment