You might argue that there is no longer a need to know anything about the DOS Command Prompt, but armed with this knowledge you should be able to understand your system as a whole much better and be able to explore more possibilities in your computing endeavors. If you follow through, understand and practice all the tutorials that I plan to list on this site, you will soon become an expert at computing. You never know when this knowledge might come in handy and you will also be able to help your friends and colleagues.
Ok, enough of why you need to have some DOS knowledge, lets get started. I will give you all the important commands that will be all you basically need to help you in any DOS "situation" that you may encounter.
Start a DOS session by clicking on
Point to All Programs
click on Command Prompt.
A DOS Window should be now open on your desktop. Well now for the first trick, to make the DOS Window display in full-screen hold down Alt and press Enter on the keyboard. To get it back to its previous state just repeat the operation again by holding down Alt and pressing Enter again. To switch back and forth between this tutorial and DOS it is best to keep the "Command Prompt" DOS session in a Window state instead of full-screen.
If you are working with Windows XP the Command Prompt should look something like the following where "UserName" will be your UserName:
C:\Documents and Settings\UserName>
I should just mention that in the old days they used the word "Directories" for what we now call "Folders". For the purpose of this tutorial I will use the old naming "Directories" instead of "Folders".
Just to make sure we are all on the same page, when I talk about Path it mean the path to the current directory. In the case of
C:\Documents and Settings\UserName>
the path indicates the drive which is
C: C Drive,
the Directory is
Documents and Settings (from win7 on
and the Subdirectory is your UserName
On your system substitute "UserName" for what ever it may be on your system.
Another use for
PATH is the
PATH environment variable on your machine. This can be set using the
PATH command or
PATH can be used to display the current settings for
PATH-variable on your system.
But for now when I talk about Path it is just the route to a specific directory or subdirectory I'm talking about and not the "PATH" environment variable or command. When I actually get to the "PATH" environment variable or command I will make sure to inform you about it.
Moving Between Directories
To maneuver your way around Directories use the
cd (think of Change Directory to easily remember it) command. The
cd .. command is used to back your way down a certain path. Now click on "Command Prompt" on the Windows Taskbar to display the Command Prompt which should currently display
C:\Documents and Settings\UserName>
cd .. and press "Enter". Now the displayed path should be
C:\Documents and Settings>
cd .. again which should take you right to the root of the drive and it should display like follow:
To work your way up the path again to the same position you started of, use the
cd command as follow:
cd Documents and Settings which will land you in
C:\Documents and Settings>
cd UserName (Remember to substitute UserName for what it is on your system) which will land you in
C:\Documents and Settings\UserName>
To go right down to the root of the drive from the current subdirectory use the cd command as follow :
If you used above
cd \ command you should now be in the root of
C: (C Drive). Just one last thing about the
cd command, when you work your way up a path using the
cd command you do not have to take it one directory at a time. I may be done as follows:
cd Documents and Settings\UserName
to land you right in the subdirectory.
cd .. (Work your way down a path)
cd \ (Take you right to the root of the drive)
cd NameOfDirectory\NameOfSubDirectory (Work your way up a path)
cd (When used on its own it just displays the current path)
Switching Between Drives
This is very easy as all you have to do at the Command Prompt is type the following and press "Enter"
D: (After typing D: press the "Enter" key to switch to D Drive)
E: (After typing E: press the "Enter" key to switch to E Drive)
F: (After typing F: press the "Enter" key to switch to F Drive)
C: (After typing C: press the "Enter" key to switch back to C Drive)
Clearing The Screen
You probably now have a DOS screen full of typing and displayed information. To clear it all just type
cls at the Command Prompt and press "Enter".
Listing Directories (Folders) And Files
dir at the Command Prompt and press "Enter" to display a listing of the Directories and Files contained in the current Directory. There is various options to use with the
dir command :
dir /p (Pause the display after every screen - Press Enter to view next screen)
dir /w (Displays in Wide Format. Date and time file created not displayed)
dir /aa (Displays only files ready for archiving)
dir /ah (Displays only hidden files)
dir /ar (Displays only read-only files)
dir /as (Displays only system files)
dir /a-a (Displays all files except files ready for archiving)
dir /a-h (Displays all files except hidden files)
dir /a-r (Displays all files except read-only files)
dir /a-s (Displays all files except system files)
Creating Directories (Folders)
If you are not currently in
C: (C Drive) type
C: and press the "Enter" key on the keyboard to take you to C Drive.
If not currently in the root of C Drive which will be displayed like this : "C:\", type
cd \ and press "Enter" to take you to the root of the drive.
mkdir MainDir and press "Enter" to create a directory MainDir in the root of
mkdir command is used to create directories. To remember it easier think of it as MakeDirectory.
dir /p command and press "Enter" to see if you can notice the MainDir directory. Note that directories will always be indicated by dir right after the date and time fields. Then type
cd MainDir to change current directory to
Note that you can use cd or CD as the case in which you type the commands does not matter.
Once inside the MainDir directory type
and press "Enter" to create a subdirectory called SubDir1 inside the MainDir parent directory. Follow it up by typing
to create a 2nd subdirectory inside the MainDir parent directory.
dir command to display a listing of your 2 subdirectories. I will get a little bit later to the issue of deleting directories as we are first going to use these subdirectories that have just been created in some exercises.
Editing Text Files
At the command prompt type
Edit and press "Enter". The MS-DOS Editor will now display in the Command Prompt Window. Type some text inside the editor window. Now click on "File" and then on "Save". Before we go any further first note the path indication just below the "File Name" label. It is indicating the current directory and path to it which should now be "C:\MainDir". In the "Directories" box, double-click on "SubDir1". Note that the path should now be "C:\MainDir\SubDir1". Click on the first dot in the field next to the "File Name" label or use the Tab key until the cursor flickers in this field. Now type File1.txt in this field and click on OK.
When ready click on "File" and then click on "New". Enter some text in the editor window and click on "File" and then on "Save". Notice the path just beneath the "File Name" label which should now be "C:\MainDir\SubDir1". However, we want to save our current information in the editor window into a new file and also in the "SubDir2" subdirectory instead of the "SubDir1" directory. In the box below "Directories" there should be 2 dots right at the top. Double click on ".." and notice that the path changed to "C:\MainDir". Doesn’t this look somehow familiar? Yes remember the CD.. command that is used to work your way backward down a path to the parent directory. It is fulfilling the same function in this "Directories" box. Next double-click on "SubDir2" and note that the path should now be "C:\MainDir\SubDir2". Use the Tab key on the keyboard until the cursor flickers in the field next to "File Name". Type File2.txt in this field and click on OK.
For the purpose of demonstrating some other commands we need to create another file. So here we go again. In the MS-DOS Editor click on "File" and then on "New". Type some text in this editor window and save it as "File3.dat" (Notice the different extension we use this time - ".dat" instead of ".txt") in "C:\MainDir\SubDir2". If you get stuck just look back at the steps in the previous paragraph. Also make double sure that it is saved in the "SubDir2" directory as we need it in that location for some of the exercises that will follow.
Now click on "File" and the on "Exit" to exit the MS-DOS Editor. You should be now back at the MS-DOS Command Prompt. Should you need to edit any of the text in the files you've just created use the Edit command. When the MS-DOS Editor displays, click on "File" and then on "Open". Use the "Directories" box to work your way up or down paths or to change drives. All files that is listed in the current directory will be listed in the "Files" box. To open a file double-click on it.
Just one last thing I would like to bring under your attention while we are still busy with the Edit command. If still in the MS-DOS Editor click on "File" and then on "Exit" to exit the MS-DOS Editor. Make use of the CD command to set the Command Prompt to "C:\MainDir\SubDir2>" if it is not the current directory. Type Edit at the Command Prompt and press the "Enter" key. Click on "File" and then on "Open". In the file name notice the following characters:
*.* which is called "wild cards". What it basically means is the any file name with any file extension will be listed in the "Files" box that is in the current directory. Change the
*.dat and press "Enter". Notice that only files with the .dat extension will be listed. Alternatively change it to
*.txt and only files with the .txt extension will be listed. We will get back to this "wild cards" at a later stage when deleting or copying files.
Using The ATTRIB Command
The ATTRIB command is used to set file attributes like making a file read-only or make it a hidden file. All the different file attributes is listed below:
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
If you are still in the MS-DOS Editor click on "File" and then on "Exit". If you followed along the Command Prompt should currently be C:\MainDir\SubDir2>. If it is not the case use the
cd .. command to change it to C:\MainDir\SubDir2>. Type
dir at the Command Prompt and make sure that the files File2.txt and File2.dat are present in this subdirectory. If it is not the case exactly repeat the steps explained in the "Editing Text Files" section. At the Command Prompt type
attrib +r File2.txt and press the "Enter" key. File2.txt should now be a read-only file. You can test this by typing
dir at the Command Prompt. Both File2.txt and File3.dat should now be listed. Now type
dir /ar at the Command Prompt and press "Enter". With this command entered like this only read-only files will be listed and you should now only see File2.txt listed.
Type Edit at the Command Prompt and click on "File" and then on "Open" in the MS-DOS Editor. Notice that the path beneath the "File Name" label should now be C:\MainDir\SubDir2. If it is not the case set it by using the Directories box. Double-click on File2.txt to open it. Try to make some changes to the text in this file, but as you will see you will be notified that the file is read-only. If you should open this file in Notepad in Windows, you will see that you can make changes to it but you will not be allowed to save it under the same name. Exit the MS-DOS Editor now. At the Command Prompt type
attrib -r File2.txt and press the "Enter" key. The read-only attribute should now be removed from the file. If you open the file now with the MS-DOS Editor you will see that changes can be made and it can be saved. Exit the MS-DOS Editor by clicking on "File" and then on "Exit".
Under normal circumstances you should never have to use the "System File Attribute" as this is reserved for system files. Therefore the only other attribute that is worth mentioning is the "Hidden File Attribute". At the Command Prompt type
attrib +h File2.txt and press the "Enter" key. Type the
dir command and notice that File2.txt will not be listed. If you however type
dir /ah it will be possible to see this file as
dir /ah displays only hidden files. Likewise in Windows you will not be able to find the file if "Folder Options" is set to "Do not show hidden files and folders". If the "Folder Options" is set to "Show hidden files and folders" then you will be able to see the file even if its hidden attribute is set. At the Command Prompt type
attrib -h File2.txt to remove the hidden attribute.
The TYPE Command
type command is use to display the contents of text files on screen. At the moment the Command Prompt should still be at C:\MainDir\SubDir2>. If not please change it accordingly. Type
type File2.txt at the Command Prompt and press "Enter". The contents of File2.txt should now be displayed. Well that is all there is to the
The COLOR Command
Lets spice up the console display with some color. Use the COLOR command to set the default console foreground and background colors. Below is a list of hex digits that represents certain colors.
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White
COLOR 3f at the command prompt and press the "Enter" key to set the console background color to aqua and the foreground color to bright white. To reset the console foreground and background colors to its default state just type
COLOR without any argument at the command prompt and press the "Enter" key.
In the few examples that is going to follow we will make use of "wild cards" again when working with files to give you more insight into their use. Make sure the Command Prompt is currently C:\MainDir\SubDir2>. If not use the
cd .. command to change it to C:\MainDir\SubDir2>.
At the Command Prompt type
move *.* C:\MainDir\SubDir1
to move the files to SubDir1. Note how you had to specify the absolute path to Subdir1. Also note the use of wild cards. The
*.* actually means All File Names with All Extensions should be moved to SubDir1. Type
dir at the Command Prompt and you will see that File2.txt and File3.dat is no longer present in SubDir2.
To continue with the exercise we should change over to SubDir1. At the Command Prompt type
cd .. which should move you back to C:\MainDir> and then type
cd SubDir1 which should move you to the C:\MainDir\SubDir1> subdirectory. Type
dir at the Command Prompt and press "Enter". File1.txt, File2.txt and File3.dat should now be present in SubDir1.
At the Command Prompt type
move *.txt C:\MainDir\SubDir2
to move only the files with an .txt extension over to SubDir2. When you do a directory listing with the
dir command you will notice that only File3.dat remains in the SubDir1 subdirectory. Just a quick reminder, you do not have to use capital letters in your commands or in the path. I'm just doing it to make it more readable.
For the purpose of this exercise we have to be back in "SubDir2" so use the
cd .. command and type "Enter" to get back to the "C:\MainDir>" parent directory. Now type
cd SubDir2 to move to the "C:\MainDir\SubDir2>" subdirectory.
Use the Dir command and notice that "File1.txt" and "File2.txt" that you previously moved here with the Move command will be present. At the Command Prompt type Copy . C:\MainDir\SubDir1 to copy all the files in "SubDir2" over to "SubDir1". You also could have used Copy *.txt C:\MainDir\SubDir1 that would have had the same effect as these were the only files present in this subdirectory.
Type Dir at the Command Prompt and notice that because you used Copy instead of Move, both files will still be present in the "SubDir2" subdirectory.
We must now change over to SubDir1. At the Command Prompt type
cd .. which should move you back to
C:\MainDir and then type
cd SubDir1 which should move you to the
C:\MainDir\SubDir1 subdirectory. Type
dir at the Command Prompt and press "Enter". "File1.txt", "File2.txt" and "File3.dat" should now be present in "SubDir1" as "File1.txt" and "File2.txt" has been copied here with the
Deleting Files With The
Just a friendly reminder, take EXTREME care with the
del command as files deleted with this command is not going to the Recycle Bin and it can NOT BE RECOVERED.
Currently the Command Prompt should be at
del *.txt and use the
dir command to see the listing. Notice that all files with the .txt extension should have been deleted by the previous command. To delete the remaining file type
del File3.dat and do a directory listing again with the
dir command. There should be no remaining files.
Now we should change over to
SubDir2. Use the
cd .. command to back down to the
C:\MainDir parent directory. Then use
SubDir2 to move to the
C:\MainDir\SubDir2 subdirectory. Do a Dir and notice that there is 2 files present in the subdirectory. Type
del *.* at the Command Prompt and do a
dir again. Notice when using the
*.* wildcards together with the
del command that All File Names with All Extensions will be deleted which will be all files present in the current directory or subdirectory.
When using the
*.* wildcards with the
del command the system might prompt you if you are sure. Just type a
n which ever may be the case and press "Enter". If you previously forgot to remove the read-only attribute from "File2.txt" access will be denied if you try to delete this file. To fix that just type
attrib -r File2.txt at the Command Prompt and press "Enter". The
del command should now work without denying you access.
Deleting Directories (Folders) With The
As in the case when deleting files with the
del command, the same goes for when deleting Directories (Folders) with the
rmdir command, please take EXTREME care with the
rmdir command as Directories (Folders) deleted with this command is not going to the Recycle Bin and it can NOT BE RECOVERED.
If you currently are in the
C:\MainDir\SubDir2 subdirectory use the
cd .. command to back down to the
C:\MainDir parent directory.
rmdir SubDir1 and press "Enter" to delete the SubDir1 subdirectory. To easily remember this command just think of
rmdir as Remove Directory. Doing a
dir will reveal that SubDir1 is deleted and only SubDir2 remains. Proceed by typing
rmdir SubDir2 to delete the SubDir2 subdirectory.
cd .. or
cd \ to back down to the root of the drive. Type
rmdir MainDir to *delete** the parent directory. Doing a
dir /p to see for yourself that it has been deleted. Just a quick reminder - the
dir /p is used to pause after every screen just in case the listing spans more than one screen.
Displaying or Setting The Date And Time
date at the Command Prompt and press "Enter". The current date will be displayed and you are offered the option to change the system date. If you want to change the date be sure to follow the format as indicated. If you do not want to make changes to the system date just press the "Enter" key without entering a new date.
To view or set the system time type Time at the Command Prompt. Type the new system time in the indicated format and press "Enter". If you do not want to make changes to the system time just press "Enter" without entering new time information.
Other Uses For The COPY Command
If working with complex print jobs see if your software supports the "Print To File" option. This option is normally supplied in the print dialog box of certain applications like Microsoft® Word, Microsoft® Excel or CorelDraw® and lots of other software products. What is nice about this trick is that if the file is very complex and printing takes a long time to process, it can now only be processed once and from then on copied to the printer port.
Another use for this "Print To File" feature is if you want the document printed on a printer that you do not have connected to your PC for instance a printer with better print quality.
Ok, lets do it by way of an exercise. Start up Microsoft® Word (On the keyboard press "Ctrl" and "Alt" simultaneously and then press "W" if you followed along with the Ultra-Fast Program Access tutorial). Do some typing and insert some colorful graphics or photos. Now one problem, your own printer's quality is maybe not exactly what you had in mind, but you can always pop over to your neighbor or a family member who got the latest and greatest of printing technology connected to their PC. Now you might be faced with another problem, your neighbor might not have the same software application that you used to produce your masterpiece in. What now? Now for the solution ...
Get hold of the Driver for the printer you plan to print to. (It might already be available in Windows XP if you go to "Control Panel", "Printers and Other Hardware" and click on "Add Printer" or download the driver from the Internet). In your newly created masterpiece in MS Word or whatever application that is supporting the "Print To File" option click on "File" and then on "Print". Select the printer that you plan to print this job for in the field next to "Name" of the Printer and click on "Print to file" to put a check mark in that selection box. Now click on OK. A "Print to file" dialog box will appear. In the left pane click on "Desktop" and in the field next to "File name" type the name of the file. For the purpose of this exercise just call it "myfile" without the quotes. This file should be now on the "Desktop". Also note that the file will have a .prn extension.
myfile.prn to your favorite external media storage and you are ready to visit your neighbour. Copy "myfile.prn" to your neighbor’s PC's Desktop. Next start the MS-DOS Command Prompt. In Windows XP it can be done by clicking on "Start", point to "All Programs", point to "Accessories" and click on "Command Prompt". The Command Prompt should be something like: "C:\Documents and Settings\UserName>" where "UserName" will be the name of the current user. Type the CD Desktop to move the Command Prompt to the Desktop directory (folder). Following is the final command to print the document on the desired printer. (For the command to work the printer must be connected to the LPT1 port).
copy /b myfile.prn lpt1 and press the "Enter" key. The results of this operation is not always as desired so please check if your document turns out as expected.
(Please note that I have not actually tested this command on a machine running Windows XP, but in theory it should work if Windows XP allows the copy operation to go ahead. I will however post an update on this tutorial, once I connect a printer to the LPT1 port of my system again).
Batch files are a quick and efficient way to automate MS-DOS tasks or commands. Make sure the Command Prompt is currently in the root of
C: (C Drive). It should display as follow:
C:\> (If not Type
CD\ at the Command Prompt and press "Enter")
notepad at the Command Prompt and press "Enter". In the MS-DOS Editor enter the following lines of text exactly as shown below with each command on a separate line. (Press the "Enter" key when at the end of a line).
In the MS-DOS Editor click on "File" then click on "Save". Next to the "File Name" label type "mybatch.bat" without the quotes in the "File Name" field and click on OK. Exit the MS-DOS Editor by clicking on "File" and then on "Exit".
At the Command Prompt type mybatch and press the "Enter" key. The batch file will execute and firstly create the "MainDir" directory in the root of the current drive. Then it will do a change directory to "C:\MainDir>". After that it will create "SubDir1" and "SubDir2" in the parent directory "MainDir" by using the MD (Make Directory) command. If you do a Dir now you will notice that you are already in the "MainDir" parent directory and the 2 created subdirectories is present. (Note that the names "MainDir", "SubDir1" and "SubDir2" I'm using is just to make explaining the exercises easier. You may use any name you desire.
The PATH Command
As I said earlier I will devote some time to this command. The PATH command is used to set or display the search path for executable files. If the Command Prompt were currently at "C:\MainDir>" and you typed Edit to launch the MS-DOS Editor, the Command Interpreter (command.com in earlier OS versions or lately cmd.exe) would not have been able to find the MS-DOS Editor program if not for the PATH statement. Type PATH at the Command Prompt and press the "Enter" key. All the different search paths will be listed. So when you type Edit at the Command Prompt the Command Interpreter will search through all these paths to find the Edit Program.
I recommend that you read through the 3 paragraphs below, but DO NOT ACTUALLY TYPE OUT AND EXECUTE THE COMMANDS if not really required. (At a later stage I will show you in one of the more advanced Windows tutorials how to safely and permanently make changes to your system's path and under what circumstances you really need to do it).
To reset the path type
PATH; at the Command Prompt and press "Enter". (DO NOT ACTUALLY DO THIS AS YOUR MACHINE MAY NOT OPERATE CORRECTLY AFTER THE PATH HAS BEEN CLEARED)
To create a new search path type for instance
PATH C:\MAINDIR at the Command Prompt and press "Enter". (NOTE HOWEVER THAT THIS WILL CLEAR ALL OTHER SEARCH PATHS AND CAUSE YOUR MACHINE TO OPERATE INCORRECTLY)
The most logical way to correctly use the path statement is to append the old PATH to your newly created path. Your machine should then still function properly. Do it as follow by typing
PATH C:\MAINDIR;%PATH% at the Command Prompt and pressing the "Enter" key. (Note that no spaces is to be used in the statement/parameters section immediately after the PATH command. There should only be one space and that is immediately after the PATH command right in front).
These settings to the systems path is only temporary. Should you mesh it up, shut down the computer and restart it to reset the PATH to its original state.
Other Important MS-DOS Commands
I'm not going to talk about the
FORMAT command in this tutorial. These command used to be very important in preparing your hard disk before loading Windows 98 or previous versions. With the widespread use and easy installation procedures of Windows XP these commands have dropped in importance as Windows XP basically leads you through the process.
To give you more insight into these 2 commands and your system as a whole, I will however in the future write a separate tutorial for them that will be intended to be practiced on an old machine and not a machine that is in everyday use.
Getting Help From DOS
I have covered by way of exercises the commands that will see you through with MS-DOS. Just in case you need more or quickly need info about one of the commands I've covered above, help is at hand directly from MS-DOS.
To get a listing of all MS-DOS commands type Help at the Command Prompt and press "Enter". Make sure the Command Prompt is not in full-screen mode otherwise you will not be able to see the complete listing. When not in full-screen mode you can use the scroll-bars at the right of the window to scroll up or down.
To get help for a specific command type
CommandName help or type
/? and press the "Enter" key. Below is some examples:
dir help or
Finally remember that you do not have to use capital letters to type out the commands.
The EXIT Command
To exit the Command Prompt session type
exit and press "Enter".
It was quite a mouthful and I certainly hoped you've learned a lot. This was the knowledge I started of with and to learn it really helped me to appreciate how everything fit together. A lot of the knowledge you gained here will even help you to better understand Windows when you use it. In the Windows tutorials that will follow you will see how to accomplish the same tasks and knowing the MS-DOS way of doing it will really give you a better understanding of everything.