|
Introduction
to the Command Line
As
the title implies, this is just an introduction to using a
Windows command prompt. It will not teach you every last
secret of using command prompts but before you're finished
here you will be able to find your way around on the command
line and do a few other things. If you are the average
Windows user you will know more when you're done reading
than you did when you started. Beginners will be less
intimidated by compiling on the command line.
Opening
a command prompt:
The
first thing you need to learn how to do is open a command
prompt. Poke around on your computer and find the command
interpreter. Earlier versions of Windows have a different
relationship to DOS that WinXP has. On XP all DOS commands
are interpreted. The interpreter uses Windows API and
interprets old DOS commands. It's my understanding that it's
not the same as DOS but it works the same as far as I can
tell. I found the command interpreter by clicking Start>Search
and searching for cmd.exe. I went to the folder that
contains cmd.exe and right clicked to make a shortcut. I
dragged the shortcut to the desktop and then right-clicked
and selected properties to set up my shortcut keys. Now all
I have to do is press my shortcut keys and up pops my
command prompt. Now you do your homework and find a way to
get to your command prompt quickly. If you have Crimson open
just press F10 and there you go. On XP you can open cmd.exe
by clicking Start,
clicking Run, typeing cmd,
and then clicking OK.
Where Am I?
If you find
yourself lost, just type CD
(by itself) and press return. That output is the path to
where you are.
What's In Here?
Type DIR
and press return. That's all the stuff in the current
directory. Every time you see <DIR>
you should know that's another directory or folder (two
words for the same thing). If that list of files and
directories is too long and goes by too fast, type DIR
/W and see what happens.
The /W stands for Wide and gives you colums that are name
only. If the file list is still too long you may want to add
/P for pause. You can mix and match here. DIR
/W /P gives you columns
and pauses. DIR
/P /W gives the same
result.
How Do I Get In
There?
So, you see a
sub-directory you want to go to (a folder in the current
directory). Just type CD
foldername (where
foldername is the name of the sub-directory) and poof,
you're there. If you want to go up one directory, type CD
..
and up you go. If you want to go to
another directory and know its full path, type CD
path
(where path is the path to the
folder you want to go to). For instance, CD
C:\windows will
take you to the windows folder on the C: drive. If you ever
find yourself too deep and just want to go to the root of
the drive, type CD
\.
Changing drives is even easier than all of this. Just type
the drive letter, colon(:) and return. The command to take
you to drive A is A:.
What
Does This Say?
Want
to see what's in a file without opening it up? Type TYPE
FILENAME.EXT
where filename is the name of the file in question and .EXT
is the file extension. Now I'm warning you that if you try
this with a large file you will just see a blur of words
rushing by, but if you are learning programming and want to
see what's in that .java or .c file, try this command. If
you really want to use this on a large file you might want
to try TYPE
FILENAME.EXT | MORE.
That | called a "pipe" and on my keyboard it is
Shift+\. Look that one up on Google. Another format for the
same result would be MORE
< FILENAME.EXT. The MORE
command feeds you the file one piece at a time and waits for
you to press return before moving on. Pressing Ctrl+C will
stop the current process. Ctrl+C is a general escape. The
< and > are "redirects" and they redirect
information on the command line. On the command line type DIR
> DirList.txt and press
return. Now if you type DIR
again you will see that there's a new file called DirList.txt.
If you open it you will see the contents of the drive
(before DirList.txt was created).
Let's
Make A Directory...
Navigate
to the root directory and type MD
MYDOSTEMP
and press return. MD stands for Make Directory and it---
makes a directory! The name of the directory is what you
type after the command. Change to the new directory by
typing CD
MYDOSTEMP.
Launch
Notepad...
Type
Notepad
and press return. You guessed it, that launched notepad. If
notepad didn't launch it could mean one of two things...
First, you might not have notepad installed. And second, the
directory notepad is in might not be listed in your PATH
sytem variable. Look in Windows help to find out about the
PATH variable and how to change it on your system. For a
little help on the way PATH should work, type HELP
PATH at
the command prompt and do a little reading. Your Windows
help and support should have more useable information. Back
to notepad now. Type something and save it as a .txt file in
C:/mydostemp and go back to the command prompt. Type DIR
and return. You should now see your text file. Type DEL
followed by your file's name and extension and press return.
Type DIR
and return again. Yep, DEL
stands for Delete. Type CD
.. and return. Type RMDIR
MYDOSTEMP
and return. Now type CD
MYDOSTEMP
and return. It can't be found? Type HELP
RMDIR and return.
I
have used the HELP command (and a lot of tinkering about) to
figure out everything you see here and a bit more. You can
pass files and commands and parameters and options, etc,
etc, right here in the command line. To pass a text file
named readme.txt to notepad you would type NOTEPAD
readme.txt.
To pass it to Edit you'd type EDIT
readme.txt.
That's assuming you're in the same directory as readme.txt.
If you're not in the same folder as the file you're passing,
then you need to pass the entire file path to the program.
Too
Much Stuff?
Type
CLS
return. That should clear up the screen.
Versions
and Help...
You
can get information about your OS and software here on the
command line.

This tells me
version information for XP, Java, and the c++ compiler. Help
for the command line and BAT files can be had by typing HELP.
C++ compiler help is c++
--help. Microsoft VC++
help is
cl /?. Checking for
version information can be a good way of testing if you have
installed a program correctly.
The Colors...
Type HELP
COLOR. Read the screen and
then start changing the colors to your preference. You can
include this in a BAT file to initialize your environment
whenever you get around to making BAT files later. I use COLOR
04 a lot and also COLOR
0C.
Title:
Type TITLE
I'M THE MAN!
That's
all there is to that.
Prompt:
This
and TYPE are the two commands I toyed with the most when I
first discovered them. I used them and BATs to make cool
little games and even animations. Save this BAT somewhere on
your computer (take off the final .txt extension) and then navigate to it on the command line.
Type jasskullyprompt.bat.
Type HELP
PROMPT and
figure out how I did it.
What
are BAT files?
These
can get quite complicated, but in their simplest forms they
are just sets of instructions to be passed to the command
interpreter rather than typing and waiting every time you
want the same set of commands executed. A very good example
of how BAT files can be used for programming can be found in
the examples that go along with Microsoft Visual C++
toolkit. If you have the toolkit installed, type CL
/?
at the command line. CL is the Microsoft compiler and /?
tells CL to give you some help. Studying the BAT files that
come with the examples along with this help can help you
along in understanding how to use command line compilers.
Windows before WindowsXP used a BAT file named autoexec.bat
to keep track of system variables. You needed to edit that
BAT and restart your computer to change system settings like
PATH. XP users click Start>Control
Panel>System>Advanced>Environment Variables
and make your changes. If that's not enough information to
make your change I suggest you find a usenet group for your
OS. Just as a warning, the BAT files that work perfectly on
one Windows system may not work the same on another.
Also
see:
Crimson
and BATs
|