Kev’s Command Prompt Cheat Sheet Article
Over the years, I’ve received messages from many a distraught beginner who was stuck because the instructions they were following made reference to the dreaded MS-DOS Command Prompt. This increasingly well-hidden feature of Windows harkens back to the days when Windows was just a thin, 16-color veil over the very basic MS-DOS operating system.
As a Web developer, there are a number of reasons you may need to use the command line in Windows. Open-source programs such as MySQL and Apache don’t always make all (or any!) of their functions available through the pretty icons and menus that Windows provides, trusting instead that developers like you and I will have a degree of command line savvy to see us through.
To run the MS-DOS Command Prompt, click on its icon in the start menu. It may be in the main Programs list or under Accessories, and may be called MS-DOS Command Prompt or just Command Prompt, depending on which version of Windows you own. In any case, once you start it up, you’ll get an ugly black window. Scary, huh?
The whole idea of the Command Prompt is you type commands after the prompt. Here’s some info to get you started with this mysterious utility:
- Type commands as you would in a text editor. You can use the left and right arrow keys and delete or backspace just as you would in Notepad. Don’t reach for the mouse, though — the command prompt is a strictly keyboard-driven affair.
- After each command, type the Enter key to execute it. Usually, a message will appear informing you of the outcome of the command you executed. Don’t feel bad if the message tells you that something was wrong with the command — displaying error messages is what the command prompt does best.
- Up and down arrows can usually be used to recall previous commands to be edited and executed again.
The command prompt itself tells you where you are on your system. For example, if your prompt looks like this:
it means that you are currently working in the
WINDOWS folder on
To get a list of all the files and sub-folders in the current folder, type the
dir command, which is short for directory, and press Enter. Here’s what this looks like when I do this (I’ll always show the part you type in bold, just so there’s no confusion):
C:WINDOWS>dir Volume in drive C is WINDOWS ME Volume Serial Number is 3436-18D4 Directory of C:WINDOWS 23/11/2001 05:09 PM <DIR> . 23/11/2001 05:09 PM <DIR> .. 23/11/2001 05:09 PM <DIR> SYSTEM 23/11/2001 05:24 PM 21,520 WINSOCK.DLL ... 249 File(s) 93,256,655 bytes 27 Dir(s) 1,141,923,840 bytes free
If your directory listing is too long to fit in the command prompt window (as will often be the case), type
/p after the
dir command (i.e. type
dir /p and then press Enter). You can then view the directory listing a page at a time, and type any key to view the next page until you reach the end of the listing.
cd command is used to change your current folder (i.e. change directory). For example, if you’re in the
C:WINDOWS folder, you can move to the
C:WINDOWSSYSTEM directory by typing
cd system and then Enter. Here’s how this looks on my computer:
C:WINDOWS>cd system C:WINDOWSSYSTEM>
See how the prompt changes to indicate the directory we are now working in?
We can return to the parent directory of the current directory (in this case,
C:WINDOWS is the parent of
C:WINDOWSSYSTEM) by typing
cd .. because
.. is a special name that always means "the parent directory of the current directory":
C:WINDOWSSYSTEM>cd .. C:WINDOWS>
You can change which drive you’re working on by typing the drive name. For example, to move to
D: drive, I do this:
See how we’re now in the root directory of D:? Now, if I had installed MySQL in
D:Program FilesMySQL, I could go to the
bin directory of my MySQL installation (
D:Program FilesMySQL) like this:
D:>cd "Program Files" D:Program Files>cd MySQL D:Program FilesMySQL>cd bin D:Program FilesMySQLbin>
Notice that I put quotes around the directory name
Program Files because it contained a space. If I hadn’t done this, the command would not have worked. The above set of three commands could have been combined into a single command like this:
D:>cd "Program FilesMySQLbin" D:Program FilesMySQLbin>
Now that you’re in your MySQL
bin directory, you can look at the files it contains with the
D:Program FilesMySQLbin> Volume in drive D is DATA1 Volume Serial Number is 18FA-3226 Directory of D:Program FilesMySQLbin 04/12/2001 03:26 PM <DIR> . 04/12/2001 03:26 PM <DIR> .. 24/11/2001 04:43 AM 1,110,016 mysqld-opt.exe 24/11/2001 05:36 AM 1,990,656 mysqld-max.exe 24/11/2001 05:30 AM 1,994,752 mysqld-max-nt.exe 24/11/2001 05:17 AM 1,118,208 mysqld-nt.exe 24/11/2001 04:12 AM 2,867,246 mysqld.exe 24/11/2001 05:38 AM 274,432 isamchk.exe 24/11/2001 05:39 AM 335,872 myisamchk.exe 24/11/2001 05:40 AM 266,240 myisamlog.exe 24/11/2001 05:41 AM 262,144 myisampack.exe 24/11/2001 04:28 AM 278,578 mysql.exe 24/11/2001 04:28 AM 237,568 mysqladmin.exe 24/11/2001 05:42 AM 237,568 mysqlbinlog.exe 21/10/2001 01:25 AM 334,712 mysqlc.exe 24/11/2001 05:42 AM 229,376 mysqlcheck.exe 24/11/2001 04:28 AM 241,664 mysqldump.exe 24/11/2001 04:28 AM 225,280 mysqlimport.exe 24/11/2001 04:29 AM 520,192 MySqlManager.exe 24/11/2001 04:29 AM 229,376 mysqlshow.exe 24/11/2001 05:44 AM 40,960 mysqlshutdown.exe 24/11/2001 05:45 AM 45,056 mysqlwatch.exe 24/11/2001 05:45 AM 229,376 pack_isam.exe 24/11/2001 05:46 AM 155,648 perror.exe 24/11/2001 05:46 AM 172,032 replace.exe 19/06/2000 03:51 AM 818 winmysqladmin.cnt 03/11/2001 01:09 AM 1,167,872 winmysqladmin.exe 19/06/2000 03:52 AM 1,856,816 WINMYSQLADMIN.HLP 26 File(s) 16,422,458 bytes 2 Dir(s) 9,239,920,640 bytes free
See all the
.exe files? Running a program from the command prompt simply involves typing its name while you’re in the directory. So in the above example I’m now ready to run such commands as
Oh, and when you’re done, you can exit a command prompt by typing