MS-DOS Tricks and Shorts

30 November -0001

Although work at the MS-DOS prompt is usually limited on most Windows machines, there are times when the command line utilities come in extremely handy. I've found some particularly useful little tricks that have helped me to deal with various disparate file management tasks and outlined them below.

Creating a Dummy File in MS-DOS

Sometimes you're working at the command line and you need to create a quick file. For instance, for the below example we're going to need two text files. The easiest way to create these files is with the 'echo' command. For instance:

>echo Test String > textfile1.txt

Will create a new file called textfile1.txt. This command sequence made use of the echo command, which mirrors whatever input is typed in back as output, and the redirect character '>' that moves the output of the first command into the file specified to the right of the operator. This operator overwrites any data that happened to be in the resultant file (if a file of the same name existed before) or creates a new file. If you want to simply add data to a file use the double greater than symbol. For instance, to append data to the file textfile1.txt use:

>echo second string >> textfile1.txt

To check the contents of the file you can use the 'more' command which will echo the contents of the file back into the command prompt. For instance:

>more textfile1.txt
Test String
second string

Concatenating Files Together in MS-DOS

Say you have two files (or twenty) named textfile1.txt and textfile2.txt. You want to create a new text file that combines the two. While you could open each file up in your favorite editor and copy and paste the text, this is time consuming and error prone. A much easier way to accomplish this task is to use the copy command:

>copy *.txt result.txt

This will take all the files with the extension .txt and create a new text file called result.txt out of all of them.

Finding Text Inside Files in MS-DOS

Lets assume I have a group of text files and I need to find out quickly which one contains the string "Test" inside it. You can quickly accomplish this using the 'find' command like so:

>find "Test" *.txt

This will search the contents of all the text files in the current directory and return a list of all of them that contain the string "Test". This command is extremely useful for searching text files.