A beginners guide to the Command Prompt

Command Prompt small imageMost Windows users don’t know what the Command Prompt is or how to use it. This is a beginners guide to using the Command Prompt.

What is the Command Prompt? The Command Prompt is a native Windows program that lets you execute commands without using a GUI. You can accomplish pretty much every task you can do using Windows and the mouse from within the Command Prompt. The Command Prompt gets its roots (arguably) from a combination of MS-DOS and UNIX. Consider it “Windows without the windows. ” I will provide you with a beginners tutorial of some simple commands to familiarize you with the Command Prompt.


The first step is to actually open the Command Prompt. You can do this by going to Start >> All Programs >> Accessories >> Command Prompt. You should get a screen that resembles mine below:
Command Prompt image

You should see a blinking cursor after a line that says C:\Documents and Settings\username. This is used to identify what directory you are currently in. This also brings us to our first three commands cd, dir, and .. (two periods). Let’s start with dir — “dir” stands for directory. Type dir into the command prompt to see a listing of the directories and files located in your “username” directory.

After you type in dir you will see a listing of several folders including Desktop, Favorites and My Documents. “CD” stands for change directory. So in order to change to our “My Documents” folder we need to type cd My Documents, give it a try. You will now notice that your path has changed to C:\Documents and Settings\username\My Documents. To see a list of all the files in your My Documents directory type dir. If you want to move back into your username folder use the “back” command. You can move back by typing cd .. See the image below:
Command Prompt image


That’s a good introduction, but lets actually go over some useful commands: copy, del, mkdir, rmdir, ren. “CP” stands for copy and it can be used to copy individual files from one location to another. To copy a file, type copy filename destination. So if you had a file named test.txt in your My Documents folder and you wanted to copy it to the Desktop you would type copy test.txt ../Desktop

The del command stands for delete. So to delete the test.txt file from your desktop type cd ../Desktop and then type del test.txt
Command Prompt image 2

“mkdir” stands for make directory. To make a new folder type mkdir foldername

“rmdir” stands for remove directory. To remove a folder and its contents, type rmdir /s foldername
Command Prompt image 3

“ren” stands for rename. To rename a file type ren oldfilename newfilename

Let’s move on to a more difficult task. Let’s copy our My Videos folder from My Documents to the Desktop. To do this, navigate to your username directory by typing cd .. until you get there. Now type cd My Documents to get into the My Documents directory. To copy the My Videos directory to the Desktop you need to type xcopy “My Videos” “../Desktop/My Videos” /s /i
Command Prompt image 4

Here’s a summary of what you can now do using the command prompt:
cd change directories

dir see a list of all the files in one directory

copy copy a file from one location to another (don’t forget to include the file extension)

del delete a file (don’t forget to include the file extension)

mkdir make a new folder

rmdir remove a directory and its’ contents

ren rename a file

xcopy /s /i copy a directory and its contents from one location to another

NOTE: To see a list of many commands, just type help into the command prompt. To see a detailed list of all related commands type command/? so to see all the details of xcopy type xcopy/? If you would like to run an executable like Mozilla Firefox navigate to the directory containing the executable and simply type it in. So type: C:/Program Files/Mozilla Firefox/firefox.exe

If you would like to learn more about the command prompt here is the documentation from Microsoft. What other commands do you think are useful for beginners? Tell your side in the comments.

Trackbacks & Pings

Comments

  1. i like the guide. i was trying to learn command prompt from so many days now i have a good guide. thanks

  2. Thank you so much.
    Best guide that I found to Command Prompt.
    Really nice job.
    Many thanks once more.

  3. Hi,

    Your guide is very good indeed, but I have a doubt… I have to run several instances of an application in a Windows server 2003. Each instance of this application should run by launching a batch command file and thus a “command prompt” window stays open. I would like to identify each “command prompt” window for example by numbering them. Instance one -window 1, instance 2-window2…Do you know how to do it ?
    Thanks,
    Marmelo

  4. Marmelo: The DOS command you are looking for is “title.”

  5. The above information on command prompt commands was excellent ! Can any one help me to find out how do I rename all the files in a folder n its subfolders with “ren” command or is theit any other way out ?
    Thank you !

  6. Ok heres one for you, I want to create a batch file that creates a new folder on the ‘Desktop’ called ‘Tidy Desktop’ but then moves not only all files but also any other folders to the newly created ‘Tidy Desktop’ folder.

    I can do everything but move any folders… This is my code thus far:

    @ECHO OFF
    MD “%systemdrive%\Documents and Settings\%USERNAME%\Desktop\Tidy Desktop”

    MOVE “%systemdrive%\Documents and Settings\%USERNAME%\Desktop\*.*” “%systemdrive%\Documents and Settings\%USERNAME%\Desktop\Tidy Desktop”

    Any help would be fab :)

  7. TinnyFusion: I think you are out of luck doing this with out-of-the-box DOS commands. The MOVE command will operate on folders, but it appears to only work for ones that are explicitly named (no wildcards), and it doesn’t actually move them (just renames them). You MIGHT be able to do it with a pair of commands (XCOPY and DEL). You’ll want to be extremely careful not to delete the shortcuts on your desktop. XCOPY has a way to pass in a list of exclusions (the shortcuts are *.LNK files), but DEL does not.

    You’ll probably have better luck with an archiving tool (Winzip, 7-Zip, etc.). Instead of moving the files and folders to a “tidy” folder, move them into a “tidy.zip” archive. Those tools all have options for deleting the original files after they have been ZIPped up, so you can do it in one stroke. If you want, you can then turn right around and unzip the files into a tidy folder, of course.

  8. PLS HELP ME MY PC CRASHED AND NOW SAYS HAL.DLL IS MISSING. IVE TREIED TO USE MY BACKUP BUT TO NO AVAIL. I AM NOW IN RECOVERY CONSOLE AND WANT TO KNOW HOW TO COPY THE MY DOCUMENTS TO CD IF POSSIBLE SO I DONT LOSE ALL MY A LEVEL WORK. PLS HELP ASAP IM DESPERATE.
    IM CURRENTLY AT C:\
    BUT IT DOESNT SEEM TO RECOGNISE
    C:\CD DOCUMENTS AND SETTINGS

  9. Hey Chris,

    I would recommend slaving your harddrive under another machine and backup your files. Don’t format your disks.

  10. Helpful
    thanks.

  11. This is great i am only 13 and i can do this stuff now thanks to your guide

  12. This is really good. Thanks. For some tricks & tips go to www.Sikkaspeaks.Blogspot.Com

  13. hey i have a problem, when i copy a folder to the desktop, cp says it copied, but i don’t see it anywhere on my desktop, why won’t it work?

  14. can you open locked files with command prompt

  15. THIS WAS USEFULL

  16. This is deffinatly the best guide on the web!! so clear and got right to the point, learnt all this stuff in a few hours and am craving more. perhaps you could send me a few more commands to try out??

    also i think you could try to explain the xcopy more clearly and show the different options( or at least some of them!) as that would have been very useful.

    But you have done an outstanding job, im only 14 and got it all very quickly :)

Post a Comment


Your email is never published nor shared. Required fields are marked *



© 2006-2007 Maxim Software Corp.  All rights reserved.