Windows
Command Prompt in 20 Minutes
What is Command Prompt?
Command Prompt (executable name
cmd.exe) is the Microsoft-supplied command-line interpreter on OS/2, Windows
CE and on Windows NT-based operating systems (including Windows 2000, XP, Vista, 7, 8, Server
2003, Server
2008,Server 2008 R2 and Server
2012). It is the analog
of COMMAND.COM in MS-DOS and Windows 9x systems
(where it is called "MS-DOS Prompt"), or of the Unix shells used
on Unix-like systems.
Source : Wikipedia.com
Advantages and Disadvantages
of Command Pompt
Advantages:
·
Traditional
operating system so less memory used.
·
Control every aspect of your computer.
·
It
is fast as compared to other operating system.
·
Good for speed if you have a slow computer.
Disadvantages
·
Not User Friendly
·
Not GUI (Graphic User Interface).
·
Many of the advantages are mainly for Linux, not so much for
Windows.
launch Command Prompt
Press Start -> Run and type cmd in
the box.
Or
You can search cmd in
the windows 7 start menu search bar and then click “cmd.exe”
It has a black terminal window.
The command prompt should look something
like:
C:\>
Here you can type you
commands.
Command prompt it NOT
CASE SENSITIVE
It does not care if
the command is of upper-case or lower case.
The “c:\>” this
shows the location where you are typing your command currently you are in the
c: drive .
Some of the command
commands :
exit: Exit the Command Prompt program and close the terminal window.
C:\>exit [Enter]
Working with Files and Directories
dir: To view the contents of a directory, type dir.
This command will list all the files and directories within the current
directory.
Same as clicking the
c: drive for seeing what folders and files it contains
C:\>dir
Volume in drive C has no label.
Volume Serial Number is EE09-D4F4
Directory of C:\
03/06/2013 11:39 PM 3,072 ads_err.adi
03/06/2013 11:39 PM 4,559 ads_err.adm
03/06/2013 11:44 PM 13,785 ads_err.adt
06/11/2012 08:49 PM
<DIR> ATI
06/11/2009 03:12 AM 24 autoexec.bat
06/11/2009 03:12 AM 10 config.sys
06/28/2013 05:49 PM 0 END
06/23/2011 08:51 AM
2,581,336,064 F.3.A.R-Black_Box.iso
07/14/2009 08:07 AM
<DIR> PerfLogs
07/16/2013 05:39 PM
<DIR> Program Files
05/15/2013 08:12 PM 43 Prova.txt
06/14/2012 11:31 PM 2,210 shared.log
05/15/2013 09:15 PM
<DIR> temp
06/11/2012 09:02 PM
<DIR> Users
07/15/2013 11:17 AM
<DIR> Windows
9 File(s) 2,581,359,767 bytes
6 Dir(s) 91,985,027,072 bytes free
Cd : Used to create directory or to move into a directory.
It is frequently useful to know in which
directory you are currently working. In order to find out, type
cd at the command
prompt.
C:\> cd
C:\
To change
directories, use the cd command with the name of a directory.
C:\> cd temp
Now, the command prompt
will be:
C:\temp>
To see what is in
this directory type:
C:\temp>dir
Volume in drive C has no label.
Volume Serial Number is EE09-D4F4
Directory of C:\temp
05/15/2013 09:15 PM
<DIR> .
05/15/2013 09:15 PM
<DIR> ..
05/17/2013 01:07 AM 112 Logfile.xml
1 File(s) 112 bytes
2 Dir(s) 91,985,022,976 bytes free
To return to the
previous directory, use the cd command, but this time followed by a
space and two periods.
C:\temp> cd ..
C:\>
mkdir: To create a new directory, use the command mkdir. The following
command creates a directory
named hello,
which you can use to to store all of your files associated with the Hello World
assignment.
C:\temp> mkdir good
To see that it
actually worked, use the dir command.
C:\temp>dir
Volume in drive C has no label.
Volume Serial Number is EE09-D4F4
Directory of C:\temp
07/22/2013 10:50 AM
<DIR> .
07/22/2013 10:50 AM
<DIR> ..
07/22/2013 10:50 AM
<DIR> good
05/17/2013 01:07 AM 112 Logfile.xml
1 File(s) 112 bytes
3 Dir(s) 91,985,022,976 bytes free
move: Now, move the two files abc.text and readme.txt into
the good directory using the move command.
C:\temp> move abc.txt hello
C:\temp> move readme.txt hello
C:\temp> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD
Directory of C:\introcs
02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/11/2005 02:53 PM DIR hello
0 File(s) 0 bytes
3 Dir(s)
The two files are no
longer visible from the current directory.
To access the two
files, change directories with the cd command. Then use the dir command
to see what
is in this new
directory.
C:\temp> cd hello
C:\temp\hello> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD
Directory of C:\temp\hello
02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 abc.java
01/17/2005 01:16 AM 256
readme.txt
2 File(s) 382 bytes
2 Dir(s)
You can also use move to
rename a file. Simply specify a new filename instead of a directory name.
Suppose you
accidentally messed up the upper and lower case and had saved abc.txt as
abc.txt. Use two move
commands to fix it.
C:\temp\good> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD
Directory of C:\temp\good
02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 abc.txt
01/17/2005 01:16 AM 256
readme.txt
2 File(s) 382 bytes
2 Dir(s)
C:\ temp\good > move abc.txt
temp.java
C:\ temp\good > move temp.txt abc.java
C:\ temp\good > dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD
Directory of C:\ temp\good
02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 abc.txt
01/17/2005 01:16 AM 256
readme.txt
2 File(s) 382 bytes
2 Dir(s)
It takes two moves
because Windows won't let you move to an already existing filename and, to Windows,
abc.txt
is the same as Abc.txt.
Copy : To make a copy of a file, use the copy command.
The following command creates a backup copy of our Abc.txt program. This is
especially useful when you modify a working program, but might want to revert
back to the original version if your modifications don't succeed.
C:\temp\good> copy Abc.txt
HelloWorld.bak
C:\temp\good> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD
Directory of C:\temp\good
02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 Abc.txt
01/17/2005 01:16 AM 256
readme.txt
2 File(s) 382 bytes
3 Dir(s)
del: Subsequently, you might want to clean up useless files. The del command
deletes a file.
C:\temp\good> del
HelloWorld.bak
C:\temp\good> dir
Volume in drive C has no label.
Volume Serial Number is C8C7-BDCD
Directory of C:\introcs
02/10/2005 08:59 PM DIR .
02/10/2005 08:59 PM DIR ..
02/03/2005 11:53 PM 126 Abc.txt
01/17/2005 01:16 AM 256
readme.txt
2 File(s) 382 bytes
3 Dir(s)
WARNING: When you revise a file in jEdit, the
jEdit program will automatically save a backup copy of your original file in the
same directory. The name of the backup file will be the name of the original
file with a ~ at the end. When you submit your program be careful to submit Abc.txt and
not Abc.txt~
which is an old version of the file and has the wrong name.
wildcards: You can also apply the copy, del,
and move
commands to several files (or directories) at once. To create a
new directory called loops, and copy all of the files in the hello directory
C:\temp\good\ into
this newly created directory type:
C:\introcs> mkdir loops
C:\introcs> copy c:\temp\good\*
loops
Here the * matches
all files in the C:\temp\good directory. It copies them to your newly
created loops directory.