Basic Command Line
Basic Command Line
Jamie Tees
So Joe gave us an exercise to do in class the other day, hopefully I can explain the steps better for
you all
If you notice we are in the C:\Windows\system32 directory. We need to create a folder in the root of
drive C:\ so we need to change directory by using the command cd. To change to a root of any drive
simply type: cd (driveletter):\
1
Command Prompt Exercise
Jamie Tees
Now we are in C:\ we are going to make the data directory by using the following command md Data
Typing dir after the md command will show the list of directories in the current folder we are in, this
is an easy way to make sure our folder is created.
^ As you can see from the following picture our Data directory is listed ! Now lets Change folders
into the Data folder then create 5 sub-folders called Monday Friday.
2
Command Prompt Exercise
Jamie Tees
So to do this we are going to cd Data to enter the data folder and then we are going to create each
directory using the md command. After we might as well check the directory using the dir command.
N.B. The arrow on your keyboard will bring back the most recent commands you have used, so if
you do a complicated command that you want repeated / edited and performed you can bring it back
with ease. (Doesnt work if you close the command prompt)
So we arent going to bother doing the screen shot as we already have listed them, and Ive provided
the screen shot . Next job, the 2 subfolders in Monday!
3
Command Prompt Exercise
Jamie Tees
So as you might remember we have been going into the directory before creating a sub directory.
But we dont actually need to do this, so for the purpose of illustration and to get you more familiar
with creating directories and files, Im going to show you another way to create a directory.
So we are in C:\Data and we want our Day and Night to be in Monday. So instead of changing
directory and then using md lets do md Monday\Day.
Okay to explain this a bit better, the computer knows there is a Monday folder so it enters it and
then creates the non-existent Day folder. Basically if we did md Monday\Day in the Data folder to
begin with, it would create that tree of folders inside Data.
This would come in really handy if you dont want to enter a directory to create a folder (if your lazy
like me). As you might have noticed, I went in to Monday and listed the directories to make sure it
was created.
4
Command Prompt Exercise
Jamie Tees
Now we have created the folders we are told to create a text file using the edit command called
schedule.txt with the lines CompTIA A+ and CompTIA Network +
So being the lazy sod I am and the fact I dont need to constantly tell you how to change directory
(Its cd if you dont remember), I will use the command edit Day\Schedule.txt This checks to see
if the Day directory is present and if it is it opens up a new editor with a new file called Schedule.txt
Okay, unfortunatly, I cant show you the edit command in operation, reason being Im on a 64 bit
version of windows 7 and the edit command isnt in the 64 bit version, stupid I know. So if all fails
lets try instead: notepad Day\Schedule.txt
5
Command Prompt Exercise
Jamie Tees
^ As you can see, this has opened notedpad and has asked us to create a new file. We will click yes
and enter the text required in the excerise.
So after putting that text into notepad, save and close notepad and then return to the CMD window.
Lets get command prompt to check whats in that file by using the command type Day\Schedule.txt
Just to remind you all as well, I typed Day\Schedule.txt because I was in the Monday folder and
didnt enter the Day folder with cd. If I was in the day folder I would have simply typed type
6
Command Prompt Exercise
Jamie Tees
Schedule.txt. Anyway as you can see after typing the command the contents of the txt file was
shown.
Right so the next thing we have to do is copy that Schedule.txt file into the Night directory. Instead
of complicating you more with putting the path in the command. Lets change directory to Day with
cd Day. Then we are going to copy the file by using the following command copy Schedule.txt
..\Night\Schedule.txt
Put simply: copy (tells the cmd to copy a file) Schedule.txt is the file that we want to copy and the
..\Night\Schedule.txt is the destination. In the destination we have a ..\ The two dots basically tell
cmd prompt to go back a directory from the current directory you are in. So we are in Day,
command prompt goes out of the Day folder back in to the Monday folder and then enters the Night
folder.
I could use ..\..\ to go back two directories, so on and so forth. This is very handy if you dont want
to type the full path. You could type: C:\Data\Monday\Night\Schedule.txt but honestly as you
might be able to tell ..\Night\Schedule.txt is way handier.
Next we are going to create a name.txt with our name in it in the night directory, so to do this we
are going to do the following command.
notepad ..\Night\name.txt
So remember we are still in the Day folder and we want to go back a directory, enter the Night
directory and create a file called name.txt.
7
Command Prompt Exercise
Jamie Tees
cd ..
cd Night
notepad name.txt
Or:
cd ..\Night
notepad name.txt
But, one command is quicker and easier than two commands so me being lazy Im going to use
notepad ..\Night\name.txt
^ So notepad opened asking to create a new file, which I clicked yes to and entered my name. Save
and exit notepad after.
Now to complicate things a tiny bit (tiny). We now have to move that name.txt into the Day folder
we are in. So to make this demonstration easier we are going to do cd ..\Night to go in to the Night
Folder. Then use: move name.txt ..\Day
8
Command Prompt Exercise
Jamie Tees
That should have moved name.txt, to check simply do a dir in the Night directory to see if its
disappeared and then a dir in the the Day directory to see if its magically being placed there
Now for a little harder part! We have to copy the entire contents of the Monday folder to the
Tuesday Friday Folders. Fun!
To do this we are going to move back to C:\Data by typing cd C:\Data then we are going to use
xcopy Monday Tuesday /e
^ This command copies everything within the Monday directory and places it in the Tuesday
directory. The /e tells the command to copy folders and subfolders including ones that are empty.
9
Command Prompt Exercise
Jamie Tees
Now we can do this command multiple times for the different folders we want the contents copied
in to!
Woot, time saver! The last command we have to perform on this excersize is the remove directory
command. And delete the Monday and Tuesday folders.
We can simply type rd Monday /s and rd Tuesday /s to quickly delete both folders, please note the
/s switch forces the rd command to delete the directory even if it has files. Without the /s you wont
be able to delete a directory that has files / subfolders.
It will ask you if your sure to delete the Monday and Tuesday folders, just type y for yes and click on
your enter key each time!
Thats it! Hoped my explanation and additions help you understand this a little better, its not too
difficult to learn if you use the commands and try them every now and again, learning off this
commands may help you at some point to diagnose / fix a computer using safe mode with command
prompt or by using the recovery console.
10