You are on page 1of 4

Command line exercise

Opening and closing a Command Prompt


Opening a Command Prompt
There are two conventional ways to start a Command prompt.

1. Start, Programs, Accessories, Command prompt


2. Start, Run and type "cmd" (minus quotes) and press enter.

There are two commands you will use most

1. "CD" (change directory) (minus quotes). This changes directory relevant to the one you are
currently working in.
2. "DIR" (directory) (minus quotes). This lists the files and directories in the folder that you are
in.
3. he "Dir" command is probably the most basic command. It gives you a listing of all the files
and folders that are located in the folder that you are currently open in.
For example, in the screenshot above, we are in the root of the C:\ drive. If a DIR command
is carried out at this point, then you will get a result similar to this:
4. Volume in drive C is System
Volume Serial Number is 1234-5678

Directory of C:\

25/10/2002 23:42 0 AUTOEXEC.BAT


26/10/2002 01:03 0 COMLOG.txt
25/10/2002 23:42 0 CONFIG.SYS
06/02/2003 15:08 0 dir.txt
04/11/2002 20:40 262,144 ntuser.dat
25/10/2002 23:49 <DIR> Documents and Settings
27/01/2003 19:58 <DIR> Program Files
27/01/2003 09:26 <DIR> WINDOWS
5 File(s) 262,144 bytes
3 Dir(s) 12,528,111,616 bytes free
5. This command does not show you any hidden files. To see hidden files you will need to use
the ATTRIB command.
6. Advanced "dir" commands
7. You can get a little more advanced with the dir command by putting extra commands after
the intitial "dir".
For example:
8. dir /s
9. will show the contents of the current folder, and any subfolders that are below. This will
produce a very long file listing. You might want to filter the results or send them to a text file
(see above).
10. dir /s something.doc
11. This command will search through all subdirectories below for a file that matches that file
name. Similarly, issuing the command
12. dir /s *.doc
13. will list all files that end in .docx (Word files).
14. More information on the DIR command can be found in the DIR Command Reference.

15. CD - Change Directory


16. The CD command is very simple to use and all commands are relative to the directory that
you are in. Therefore if you want to change to the "Windows" directory, you would type
17. CD Windows
18. If you then wanted to change to the "system" directory (which is a sub directory of
"windows"), you would enter
19. CD System
20. However if you knew that you wanted to change to the system directory immediately, you
could type this command instead:
21. CD Windows\System
22. However if you were already deep in another directory (for example c:\ documents and
settings) and then wanted to move directly to windows\system then you can do that by
putting in an initial backwards slash:
23. CD \Windows\System
24. This tells the command to go to the root of the drive, then to the directory Windows and
system.
25. Moving Back Up
26. You can also move back up the tree, instead of down.
27. If you want to just return to the root of the drive (C:\) you would just type
28. cd \ or cd\
29. If you wanted to just go back one level (to use the earlier example, you were in
c:\windows\system and you wanted to be in c:\windows) you would just type:
30. cd..
31. Alternatively, if you want to access a totally different directory, for example "Program Files"
you could type
32. cd program files or cd "program files"
33. When typing directories to change to, if the directory name is unique, then you can use wild
cards. For example
34. cd program*
35. Directory Entry Shortcut: : If you are on Windows 2000 or XP and you have a Windows
Explorer screen open at the location that you want to run a Command Prompt command you
could open the Command Prompt and typing a long series of directories or CD commands.
Instead, just type CD and then a space, then drag and drop the directory you want to work in
to the Command Prompt window. The full path to the directory will be entered, ready for you
to press enter.
36. More information on the CD command can be found in the CD Command Reference.

37. Change Drive


38. If you want to run a command against a directory on another drive, such as the D drive, then
you need to change to that drive, This is done simply by entering the drive letter and a colon:
39. d:
40. On Windows Vista and higher you can also combine the drive letter change and directory by
using the full path:
41. cd d:\downloads
42. On Windows XP and older, you can still enter the above command, but will then need to do
d: . When you do, you will find that you are in the directory where you did the CD command
to.

43. File Renaming


44. You can rename files in a command prompt.
45. rename something.txt someone.txt
46. would rename the file something.txt to someone.txt
47. Full Rename Command Reference.

48. Directory Creation


49. You can create directories from the command prompt:
50. mkdir something
51. would create a directory called "something".
If you want a directory with a name that has a space in it, such as "My Files" you need
include the command in " ":
52. mkdir "my files"
53. This ensures that the directory is created with the space. Without the space you will get a
new directory called "my" and an error message.
54. You can also use the md command instead of mkdir.

55. Deleting Files and Folders


56. If you want to delete a file, then just type:
57. del filename.ext
58. If you want to delete all files in a folder then type
59. del *.*
60. similarly if you want to delete all files with a certain extension, then type
61. del *.ext
62. (where ext is the extension you want to delete)
63. To delete a folder, simply enter
64. del foldername
65. There are more advanced options for deleting files through the Command Prompt - view
the Command Reference for DEL to see the full list.
66. Note - if you delete a file within a Command Prompt session it does not go in to the recycle
bin. It will be deleted immediately.

You might also like