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:
C:WINDOWS>
it means that you are currently working in the WINDOWS
folder on C:
drive.
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.
The 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:
C:WINDOWS>d:
D:>
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 dir
command:
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 mysqld
, mysqladmin
and mysql
.
Oh, and when you’re done, you can exit a command prompt by typing exit
.
Frequently Asked Questions (FAQs) about Command Prompt Cheat Sheet
What is the significance of the command prompt in Windows?
The command prompt is a crucial feature in Windows operating systems. It is a command-line interpreter application that interprets and executes commands inputted by users. It allows users to perform tasks more efficiently and quickly than using the graphical user interface. It is especially useful for system administrators and developers who need to manage files, directories, and software on their computers or networks.
How can I access the command prompt in Windows?
To access the command prompt in Windows, click on the Start button and type ‘cmd’ in the search bar. Click on the ‘Command Prompt’ application that appears in the search results. Alternatively, you can press the Windows key + R to open the ‘Run’ dialog box, type ‘cmd’, and press Enter.
What are some basic commands I can use in the command prompt?
There are numerous commands you can use in the command prompt. Some basic ones include ‘dir’ to list the contents of a directory, ‘cd’ to change directories, ‘del’ to delete a file, ‘copy’ to copy a file, and ‘move’ to move a file. Each command has its own set of options and arguments, which you can view by typing the command followed by ‘/?’.
How can I customize the command prompt window?
You can customize the command prompt window by right-clicking on the title bar and selecting ‘Properties’. Here, you can change the font, color, and size of the command prompt window, as well as enable quick edit mode, which allows you to copy and paste text directly in the command prompt.
Can I run multiple commands at once in the command prompt?
Yes, you can run multiple commands at once in the command prompt by separating them with the ‘&’ symbol. For example, ‘dir & cd..’ will list the contents of the current directory and then move up one directory.
How can I redirect the output of a command to a file?
You can redirect the output of a command to a file by using the ‘>’ symbol. For example, ‘dir > output.txt’ will save the output of the ‘dir’ command to a file named ‘output.txt’.
What is the difference between ‘copy’ and ‘xcopy’ commands?
The ‘copy’ command is used to copy files, while the ‘xcopy’ command is used to copy directories, subdirectories, and files. The ‘xcopy’ command also has more options and is more powerful than the ‘copy’ command.
How can I run a command as an administrator in the command prompt?
To run a command as an administrator in the command prompt, you need to open the command prompt as an administrator. To do this, right-click on the ‘Command Prompt’ application and select ‘Run as administrator’.
Can I use the command prompt to troubleshoot network issues?
Yes, the command prompt has several commands that can help troubleshoot network issues. For example, the ‘ping’ command can check the connectivity to a network host, the ‘ipconfig’ command can display the IP configuration for all network interfaces, and the ‘netstat’ command can display active network connections.
How can I get help on a specific command in the command prompt?
To get help on a specific command in the command prompt, type the command followed by ‘/?’. For example, ‘copy /?’ will display help for the ‘copy’ command.
Kevin Yank is an accomplished web developer, speaker, trainer and author of Build Your Own Database Driven Website Using PHP & MySQL and Co-Author of Simply JavaScript and Everything You Know About CSS is Wrong! Kevin loves to share his wealth of knowledge and it didn't stop at books, he's also the course instructor to 3 online courses in web development. Currently Kevin is the Director of Front End Engineering at Culture Amp.