Você está na página 1de 11

ms-dos tutorial - mastering the command

prompt
you might argue that there is no longer a need to know anything about the dos
command prompt, but armed with this knowledge you should be able to understand
your system as a whole much better and be able to explore more possibilities in your
computing endeavors. if you follow through, understand and practice all the tutorials
that i plan to list on this site, you will soon become an expert at computing. you
never know when this knowledge might come in handy and you will also be able to
help your friends and colleagues.

ok, enough of why you need to have some dos knowledge, lets get started. i will give
you all the important commands that will be all you basically need to help you in any
dos "situation" that you may encounter.

start a dos session by clicking on start, point to all programs, accessories and then click
on command prompt. in the "ultra-fast program access tutorial" you can learn how to set
up your system to instantly activate the command prompt, just press "ctrl" and "alt" and
while still holding them down press "d".
a dos window should be now open on your desktop. well now for the first trick, to make
the dos window display in full-screen hold down "alt" and press "enter" on the keyboard.
to get it back to its previous state just repeat the operation again by holding down "alt"
and pressing "enter" again. to switch back and forth between this tutorial and dos it is
best to keep the "command prompt" dos session in a window state instead of full-screen.
if you are working with windows xp the command prompt should look something like the
following where "username" will be your user name:
c:\documents and settings\username>_
i should just mention that in the old days they used the word "directories" for what we
now call "folders". for the purpose of this tutorial i will use the old naming "directories"
instead of "folders".
just to make sure we are all on the same page, when i talk about "path" it mean the path to
the current directory. in the case of "c:\documents and settings\username>" the path
indicates the drive which is "c:" (c drive), the directory is "documents and settings" and
the subdirectory is "username". on your system substitute "username" for what ever it
may be on your system.
another use for "path" is the "path" environment variable on your machine. this can be set
using the "path" command or "path" can be used to display the current settings for "path"
on your system. but for now when i talk about "path" it is just the "route" to a
specific directory or subdirectory i'm talking about and not the "path" environment
variable or command. when i actually get to the "path" environment variable or
command i will make sure to inform you about it.

moving between directories


to maneuver your way around directories use the cd (think of change directory to easily
remember it) command. the cd.. command is used to back your way down a certain path.
now click on "command prompt" on the windows taskbar to display the command
prompt which should currently display "c:\documents and settings\username>". type cd..
and press "enter". now the displayed path should be "c:\documents and settings>". type
cd.. again which should take you right to the root of the drive and it should display like
follow: "c:\>".
to work your way up the path again to the same position you started of, use the cd
command as follow: cd documents and settings which will land you in "c:\documents
and settings>". then type cd username (remember to substitute username for what it is on
your system) which will land you in "c:\documents and settings\username>".
to go right down to the root of the drive from the current subdirectory use the cd
command as follow: cd\
if you used above cd\ command you should now be in the root of c: (c drive). just one last
thing about the cd command, when you work your way up a path using the cd command
you do not have to take it one directory at a time. i may be done as follow: cd documents
and settings\username to land you right in the subdirectory.
lets summarize:
cd.. (work your way down a path)
cd\ (take you right to the root of the drive)
cd nameofdirectory\nameofsubdirectory (work your way up a path)
cd (when used on its own it just displays the current path)

switching between drives


this is very easy as all you have to do at the command prompt is type the following and
press "enter"
d: (after typing d: press the "enter" key to switch to d drive)
e: (after typing e: press the "enter" key to switch to e drive)
f: (after typing f: press the "enter" key to switch to f drive)
c: (after typing c: press the "enter" key to switch back to c drive)

clearing the screen


you probably now have a dos screen full of typing and displayed information. to clear it
all just type cls at the command prompt and press "enter".

listing directories (folders) and files


type dir at the command prompt and press "enter" to display a listing of the directories
and files contained in the current directory.
there is various options to use with the dir command:
dir /p (pause the display after every screen - press enter to view next screen)
dir /w (displays in wide format. date and time file created not displayed)
dir /aa (displays only files ready for archiving)
dir /ah (displays only hidden files)
dir /ar (displays only read-only files)
dir /as (displays only system files)
dir /a-a (displays all files except files ready for archiving)
dir /a-h (displays all files except hidden files)
dir /a-r (displays all files except read-only files)
dir /a-s (displays all files except system files)

creating directories (folders)


if you are not currently in c: (c drive) type c: and press the "enter" key on the keyboard to
take you to c drive. also if not currently in the root of c drive (which will be displayed
like this: "c:\>") type cd\ and press "enter" to take you to the root of the drive. now type
md maindir and press "enter" to create the in the root of c:\ the maindir directory. the md
command is used to create directories. to remember it easier think of it as make directory.
type the dir /p command and press "enter" to see if you can notice the maindir directory.
note that directories will always be indicated by <dir> right after the date and time fields.
then type cd maindir to change current directory to c:>\maindir>. (note that you can use
cd or cd as the case in which you type the commands does not matter).
once inside the maindir directory type md subdir1 and press "enter" to create a
subdirectory called subdir1 inside the maindir parent directory. follow it up by typing md
subdir2 to create a 2nd subdirectory inside the maindir parent directory.
use the dir command to display a listing of your 2 subdirectories. i will get a little bit
later to the issue of deleting directories as we are first going to use these subdirectories
that have just been created in some exercises.
editing text files
at the command prompt type edit and press "enter". the ms-dos editor will now display in
the command prompt window. type some text inside the editor window. now click on
"file" and then on "save". before we go any further first note the path indication just
below the "file name" label. it is indicating the current directory and path to it which
should now be "c:\maindir". in the "directories" box, double-click on "subdir1". note that
the path should now be "c:\maindir\subdir1". click on the first dot in the field next to the
"file name" label or use the tab key until the cursor flickers in this field. now type
file1.txt in this field and click on ok.
when ready click on "file" and then click on "new". enter some text in the editor window
and click on "file" and then on "save". notice the path just beneath the "file name" label
which should now be "c:\maindir\subdir1". however, we want to save our current
information in the editor window into a new file and also in the "subdir2" subdirectory
instead of the "subdir1" directory. in the box below "directories" there should be 2 dots
right at the top. double click on ".." and notice that the path changed to "c:\maindir".
doesn’t this look somehow familiar? yes remember the cd.. command that is used to work
your way backward down a path to the parent directory. it is fulfilling the same function
in this "directories" box. next double-click on "subdir2" and note that the path should
now be "c:\maindir\subdir2". use the tab key on the keyboard until the cursor flickers in
the field next to "file name". type file2.txt in this field and click on ok.
for the purpose of demonstrating some other commands we need to create another file. so
here we go again. in the ms-dos editor click on "file" and then on "new". type some text
in this editor window and save it as "file3.dat" (notice the different extension we use
this time - ".dat" instead of ".txt") in "c:\maindir\subdir2". if you get stuck just look
back at the steps in the previous paragraph. also make double sure that it is saved in the
"subdir2" directory as we need it in that location for some of the exercises that will
follow.
now click on "file" and the on "exit" to exit the ms-dos editor. you should be now back at
the ms-dos command prompt. should you need to edit any of the text in the files you've
just created use the edit command. when the ms-dos editor displays, click on "file" and
then on "open". use the "directories" box to work your way up or down paths or to
change drives. all files that is listed in the current directory will be listed in the "files"
box. to open a file double-click on it.
just one last thing i would like to bring under your attention while we are still busy with
the edit command. if still in the ms-dos editor click on "file" and then on "exit" to exit the
ms-dos editor. make use of the cd command to set the command prompt to
"c:\maindir\subdir2>" if it is not the current directory. type edit at the command prompt
and press the "enter" key. click on "file" and then on "open". in the file name notice the
following characters: *.* which is called "wild cards". what it basically means is the any
file name with any file extension will be listed in the "files" box that is in the current
directory. change the *.* to *.dat and press "enter". notice that only files with the .dat
extension will be listed. alternatively change it to *.txt and only files with the .txt
extension will be listed. we will get back to this "wild cards" at a later stage when
deleting or copying files.

using the attrib command


the attrib command is used to set file attributes like making a file read-only or make it a
hidden file. all the different file attributes is listed below:
r read-only file attribute.
a archive file attribute.
s system file attribute.
h hidden file attribute.
if you are still in the ms-dos editor click on "file" and then on "exit". if you followed
along the command prompt should currently be "c:\maindir\subdir2>". if it is not the case
use the cd or cd.. command to change it to "c:\maindir\subdir2>". type dir at the
command prompt and make sure that the files "file2.txt" and "file2.dat" are present in this
subdirectory. if it is not the case exactly repeat the steps explained in the "editing text
files" section. at the command prompt type attrib +r file2.txt and press the "enter" key.
file2.txt should now be a read-only file. you can test this by typing dir at the command
prompt. both "file2.txt" and "file3.dat" should now be listed. now type dir /ar at the
command prompt and press "enter". with this command entered like this only read-only
files will be listed and you should now only see "file2.txt" listed.
type edit at the command prompt and click on "file" and then on "open" in the ms-dos
editor. notice that the path beneath the "file name" label should now be
"c:\maindir\subdir2". if it is not the case set it by using the directories box. double-click
on "file2.txt" to open it. try to make some changes to the text in this file, but as you will
see you will be notified that the file is read-only. if you should open this file in notepad in
windows, you will see that you can make changes to it but you will not be allowed to
save it under the same name. exit the ms-dos editor now. at the command prompt type
attrib -r file2.txt and press the "enter" key. the read-only attribute should now be
removed from the file. if you open the file now with the ms-dos editor you will see that
changes can be made and it can be saved. exit the ms-dos editor by clicking on "file" and
then on "exit".
under normal circumstances you should never have to use the "system file attribute" as
this is reserved for system files. therefore the only other attribute that is worth mentioning
is the "hidden file attribute". at the command prompt type attrib +h file2.txt and press
the "enter" key. type the dir command and notice that "file2.txt" will not be listed. if you
however type dir /ah it will be possible to see this file as dir /ah displays only hidden
files. likewise in windows you will not be able to find the file if "folder options" is set to
"do not show hidden files and folders". if the "folder options" is set to "show hidden files
and folders" then you will be able to see the file even if its hidden attribute is set. at the
command prompt type attrib -h file2.txt to remove the hidden attribute.

the type command


the type command is use to display the contents of text files on screen. at the moment the
command prompt should still be at "c:\maindir\subdir2>". if not please change it
accordingly. type type file2.txt at the command prompt and press "enter". the contents of
"file2.txt" should now be displayed. well that is all there is to the type command.

the color command


lets spice up the console display with some color. use the color command to set the
default console foreground and background colors. below is a list of hex digits that
represents certain colors.
0 = black
1 = blue
2 = green
3 = aqua
4 = red
5 = purple
6 = yellow
7 = white
8 = gray
9 = light blue
a = light green
b = light aqua
c = light red
d = light purple
e = light yellow
f = bright white
type color 3f at the command prompt and press the "enter" key to set the console
background color to aqua and the foreground color to bright white. to reset the console
foreground and background colors to its default state just type color without any
argument at the command prompt and press the "enter" key.

moving files
in the few examples that is going to follow we will make use of "wild cards" again when
working with files to give you more insight into their use. make sure the command
prompt is currently "c:\maindir\subdir2>". if not use the cd or cd.. command to change it
to "c:\maindir\subdir2>". at the command prompt type move *.* c:\maindir\subdir1 to
move the files to "subdir1". note how you had to specify the absolute path to subdir1. also
note the use of wild cards. the *.* actually means all file names with all extensions
should be moved to subdir1. type dir at the command prompt and you will see that
"file2.txt" and "file3.dat" is no longer present in "subdir2".
to continue with the exercise we should change over to subdir1. at the command prompt
type cd.. which should move you back to "c:\maindir>" and then type cd subdir1 which
should move you to the "c:\maindir\subdir1>" subdirectory. type dir at the command
prompt and press "enter". "file1.txt", "file2.txt" and "file3.dat" should now be present in
"subdir1".
at the command prompt type move *.txt c:\maindir\subdir2 to move only the files with
an .txt extension over to "subdir2". when you do a directory listing with the dir command
you will notice that only "file3.dat" remains in the "subdir1" subdirectory. just a quick
reminder, you do not have to use capital letters in your commands or in the path. i'm just
doing it to make it more readable.

copying files
for the purpose of this exercise we have to be back in "subdir2" so use the cd.. command
and type "enter" to get back to the "c:\maindir>" parent directory. now type cd subdir2 to
move to the "c:\maindir\subdir2>" subdirectory.
use the dir command and notice that "file1.txt" and "file2.txt" that you previously moved
here with the move command will be present. at the command prompt type copy *.*
c:\maindir\subdir1 to copy all the files in "subdir2" over to "subdir1". you also could
have used copy *.txt c:\maindir\subdir1 that would have had the same effect as these
were the only files present in this subdirectory.
type dir at the command prompt and notice that because you used copy instead of move,
both files will still be present in the "subdir2" subdirectory.
we must now change over to "subdir1". at the command prompt type cd.. which should
move you back to "c:\maindir>" and then type cd subdir1 which should move you to the
"c:\maindir\subdir1>" subdirectory. type dir at the command prompt and press "enter".
"file1.txt", "file2.txt" and "file3.dat" should now be present in "subdir1" as "file1.txt" and
"file2.txt" has been copied here with the copy command.

deleting files with the del command


just a friendly reminder, take extreme care with the del command as files deleted with
this command is not going to the recycle bin and it can not be recovered.
currently the command prompt should be at "c:\maindir\subdir1>". type del *.txt and use
the dir command to see the listing. notice that all files with the .txt extension should have
been deleted by the previous command. to delete the remaining file type del file3.dat and
do a directory listing again with the dir command. there should be no remaining files.
now we should change over to "subdir2". use the cd.. command to back down to the
"c:\maindir>" parent directory. then use cd subdir2 to move to the "c:\maindir\subdir2>"
subdirectory. do a dir and notice that there is 2 files present in the subdirectory. type del
*.* at the command prompt and do a dir again. notice when using the *.* wildcards
together with the del command that all file names with all extensions will be deleted
which will be all files present in the current directory or subdirectory.
when using the *.* wildcards with the del command the system might prompt you if you
are sure. just type a y or n which ever may be the case and press "enter". if you
previously forgot to remove the read-only attribute from "file2.txt" access will be denied
if you try to delete this file. to fix that just type attrib -r file2.txt at the command prompt
and press "enter". the del command should now work without denying you access.
deleting directories (folders) with the rd command
as in the case when deleting files with the del command, the same goes for when deleting
directories (folders) with the rd command, please take extreme care with the rd
command as directories (folders) deleted with this command is not going to the recycle
bin and it can not be recovered.
if you currently are in the "c:\maindir\subdir2>" subdirectory use the cd.. command to
back down to the "c:\maindir>" parent directory.
type rd subdir1 and press "enter" to delete the "subdir1" subdirectory. to easily
remember this command just think of rd as remove directory. doing a dir will reveal that
"subdir1' is deleted and only "subdir2" remain. proceed by typing rd subdir2 to delete
the "subdir2" subdirectory.
now type cd.. or cd\ to back down to the root of the drive. type rd maindir to delete the
parent directory. doing a dir /p to see for yourself that it has been deleted. just a quick
reminder - the dir /p is used to pause after every screen just in case the listing spans more
than one screen.

displaying or setting the date and time


type date at the command prompt and press "enter". the current date will be displayed
and you are offered the option to change the system date. if you want to change the date
be sure to follow the format as indicated. if you do not want to make changes to the
system date just press the "enter" key without entering a new date.
to view or set the system time type time at the command prompt. type the new system
time in the indicated format and press "enter". if you do not want to make changes to the
system time just press "enter" without entering new time information.

other uses for the copy command


if working with complex print jobs see if your software supports the "print to file" option.
this option is normally supplied in the print dialog box of certain applications like
microsoft® word, microsoft® excel or coreldraw® and lots of other software products.
what is nice about this trick is that if the file is very complex and printing takes a long
time to process, it can now only be processed once and from then on copied to the printer
port.
another use for this "print to file" feature is if you want the document printed on a printer
that you do not have connected to your pc for instance a printer with better print quality.
ok, lets do it by way of an exercise. start up microsoft® word (on the keyboard press
"ctrl" and "alt" simultaneously and then press "w" if you followed along with the ultra-
fast program access tutorial). do some typing and insert some colorful graphics or photos.
now one problem, your own printer's quality is maybe not exactly what you had in mind,
but you can always pop over to your neighbor or a family member who got the latest and
greatest of printing technology connected to their pc. now you might be faced with
another problem, your neighbor might not have the same software application that you
used to produce your masterpiece in. what now? now for the solution ...
get hold of the driver for the printer you plan to print to. (it might already be available in
windows xp if you go to "control panel", "printers and other hardware" and click on "add
printer" or download the driver from the internet). in your newly created masterpiece in
ms word or whatever application that is supporting the "print to file" option click on
"file" and then on "print". select the printer that you plan to print this job for in the field
next to "name" of the printer and click on "print to file" to put a check mark in that
selection box. now click on ok. a "print to file" dialog box will appear. in the left pane
click on "desktop" and in the field next to "file name" type the name of the file. for the
purpose of this exercise just call it "myfile" without the quotes. this file should be now on
the "desktop". also note that the file will have a .prn extension.
now copy "myfile.prn" to your favorite external media storage and you are ready to visit
your neighbour. copy "myfile.prn" to your neighbor’s pc's desktop. next start the ms-dos
command prompt. in windows xp it can be done by clicking on "start", point to "all
programs", point to "accessories" and click on "command prompt". the command prompt
should be something like: "c:\documents and settings\username>" where "username" will
be the name of the current user. type the cd desktop to move the command prompt to the
desktop directory (folder). following is the final command to print the document on the
desired printer. (for the command to work the printer must be connected to the lpt1 port).
type copy /b myfile.prn lpt1 and press the "enter" key. the results of this operation is not
always as desired so please check if your document turns out as expected.
(please note that i have not actually tested this command on a machine running windows
xp, but in theory it should work if windows xp allows the copy operation to go ahead. i
will however post an update on this tutorial, once i connect a printer to the lpt1 port of
my system again).

batch files
batch files are a quick and efficient way to automate ms-dos tasks or commands. make
sure the command prompt is currently in the root of c: (c drive). it should display as
follow: c:\> (if not type cd\ at the command prompt and press "enter")
type edit at the command prompt and press "enter". in the ms-dos editor enter the
following lines of text exactly as shown below with each command on a separate line.
(press the "enter" key when at the end of a line).
md maindir
cd maindir
md subdir1
md subdir2
in the ms-dos editor click on "file" then click on "save". next to the "file name" label type
"mybatch.bat" without the quotes in the "file name" field and click on ok. exit the ms-dos
editor by clicking on "file" and then on "exit".
at the command prompt type mybatch and press the "enter" key. the batch file will
execute and firstly create the "maindir" directory in the root of the current drive. then it
will do a change directory to "c:\maindir>". after that it will create "subdir1" and
"subdir2" in the parent directory "maindir" by using the md (make directory) command.
if you do a dir now you will notice that you are already in the "maindir" parent directory
and the 2 created subdirectories is present. (note that the names "maindir", "subdir1" and
"subdir2" i'm using is just to make explaining the exercises easier. you may use any name
you desire.

the path command


as i said earlier i will devote some time to this command. the path command is used to
set or display the search path for executable files. if the command prompt were currently
at "c:\maindir>" and you typed edit to launch the ms-dos editor, the command interpreter
(command.com in earlier os versions or lately cmd.exe) would not have been able to find
the ms-dos editor program if not for the path statement. type path at the command
prompt and press the "enter" key. all the different search paths will be listed. so when you
type edit at the command prompt the command interpreter will search through all these
paths to find the edit program.
i recommend that you read through the 3 paragraphs below, but do not actually
type out and execute the commands if not really required. (at a later stage i will show
you in one of the more advanced windows tutorials how to safely and permanently make
changes to your system's path and under what circumstances you really need to do it).
to reset the path type path; at the command prompt and press "enter". (do not actually
do this as your machine may not operate correctly after the path has been cleared)
to create a new search path type for instance path c:\maindir at the command prompt
and press "enter". (note however that this will clear all other search paths and cause
your machine to operate incorrectly)
the most logical way to correctly use the path statement is to append the old path to your
newly created path. your machine should then still function properly. do it as follow by
typing path c:\maindir;%path% at the command prompt and pressing the "enter" key.
(note that no spaces is to be used in the statement/parameters section immediately after
the path command. there should only be one space and that is immediately after the path
command right in front).
these settings to the systems path is only temporary. should you mesh it up, shut down the
computer and restart it to reset the path to its original state.

other import ms-dos commands


i'm not going to talk about the fdisk and format command in this tutorial. these command
used to be very important in preparing your hard disk before loading windows 98 or
previous versions. with the widespread use and easy installation procedures of windows
xp these commands have dropped in importance as windows xp basically leads you
through the process.
to give you more insight into these 2 commands and your system as a whole, i will
however in the future write a separate tutorial for them that will be intended to be
practiced on an old machine and not a machine that is in everyday use.

getting help from dos


i have covered by way of exercises the commands that will see you through with ms-dos.
just in case you need more or quickly need info about one of the commands i've covered
above, help is at hand directly from ms-dos.
to get a listing of all ms-dos commands type help at the command prompt and press
"enter". make sure the command prompt is not in full-screen mode otherwise you will not
be able to see the complete listing. when not in full-screen mode you can use the scroll-
bars at the right of the window to scroll up or down.
to get help for a specific command type commandname help or type commandname /?
and press the "enter" key. below is some examples:
dir help
or
copy /?
finally remember that you do not have to use capital letters to type out the commands.

the exit command


to exit the command prompt session type exit and press "enter".

final word
it was quite a mouthful and i certainly hoped you've learned a lot. this was the knowledge
i started of with and to learn it really helped me to appreciate how everything fit together.
a lot of the knowledge you gained here will even help you to better understand windows
when you use it. in the windows tutorials that will follow you will see how to accomplish
the same tasks and knowing the ms-dos way of doing it will really give you a better
understanding of everything.

Você também pode gostar