Lab: The Command Line Objectives: customize the command line use DOS commands to view, navigate, create and delete directories use DOS commands to copy, move, rename, delete files and change attributes Background: All computer and network technicians should know some of the basic commands and functions available from the command line in Windows. Microsoft’s Disk Operating System (DOS), also called MS-DOS, is a collection of programs and commands used to control the overall computer operation in a disk-based system. All modern Windows versions support DOS commands from the command line. DOS allows you to even edit the command line and change the way it behaves. Step 1: The Command Line Open a command line from Windows: select Start/Run and type: command 1. What directory are you in? ________________ 2. What does the prompt look like? ___________ Task: The Prompt: The DOS prompt is what you see when you first open a command line window. The default prompt is C:\, or your current patch. The prompt can be changed, using the prompt command. The prompt command uses the syntax prompt text, where text can be anything you want. There are also several preconfigured prompt parameters you can use. Try changing the prompt using the following commands: Command What is displayed at the prompt? prompt $q ____________ prompt $$ ____________ prompt $t ____________ prompt $d ____________ $p ____________ $v ____________ prompt <Your Name>’s PC $d $p ____________ Change your prompt back to the default to finish the lab: prompt $p$g Task: Editing the Command Line Dos lets you edit the command line, and even recall previous commands to make changes if needed. In order to use command line editing, you use a TSR called doskey, which must be initialized. A TSR (terminate-and-stay-resident) program that loads itself into memory and stays there until you restart your computer. type: doskey (doskey is now loaded and you can use it to recall commands) Now we will enter some commands into the history list, so we can try it out type: cd\ type: cd windows type: cd command Now try some of the command history features: press the up arrow scroll back up through your list of commands press the down arrow to scroll back down through the list press Esc to clear the current command press F7 to list the commands you have typed press F9 and then enter the number of the command you want to use Try some of the editing keys to edit commands: home: moves to the beginning of the line right and left arrow: moves forward and back 1 character at a time end: moves to the end of the line ctrl + right or left arrow: moves forward or back a word Ins: lets you add characters Step 2: Displaying Directory Contents: Dir DIR command will list directories and various files. Directories are specified with the <DIR> notation that precedes the file/directory. The DIR command also displays the volume name, free space, and total files and directories present. Task: show a list of the directories located on this drive. type: cd\ change to the root directory type: cd windows change to the windows directory type dir What happened?_______________________________________ type: dir /p Press enter to continue the list How many directories do you have in the windows folder? _____________________________ What does the /p switch do? _______________ Task: get help on the dir command: type: cd\ change to the root directory type: dir /? What does the /w switch do? _______________ What does the /s switch do? _________________ Task: find a file using dir/s : type: dir /s format.com Where is the file located? __________________ You can also use a wildcard to search for files. The * is a wildcard which can be used in place of all or part of a filename, to use a command on many files at once. The * wildcard replaces any number of letters before or after the dot in a filename. Task: search for the readme files on your drive type: dir /s/p readme.* How many files did it find? ________________ Step 3: Create a directory To create directories in DOS, use the md directory_name or mkdir directory_name command. Task: create an IT directory in the C drive type: cd\ change to the root directory type: md it Task: verify the creation of the directory type: dir Is the it directory in the list? _______________________________ Step 4: Changing Directories To change directories use the cd directory_name command. To move up one level in the directory structure, use the command cd… Task: change to the it directory type: cd it The command prompt should now be C:\it >. Step 5: Create another directory Task: create another directory called “pcs”, inside the IT directory type: md pcs Task: verify the creation of the directory type: dir Is the pcs directory in the list? _______________________________ Step 6 Task: Change to the newly created “pcs” directory. type: cd pcs The command prompt should now be c:\IT\pcs> Step 7: Create files To create a file in DOS, use the copy con filename command. This command will copy the text from the console and make it into a new directory. After you type this command you will have a blank line on the command prompt. You can then type in text that will be saved in the newly created file. When you are finished typing in your message, hold down the Control Key (<Ctrl>) press the Z key and then press the Enter key. This key combination will end the message and DOS will display “1 file(s) copied”. Task: Create new files from the console Type: copy con sample1.txt type in a few words Press Ctrl + Z, then enter Type: copy con sample2.txt type in a few words Press Ctrl + Z, then enter Type: copy con sample3.txt type in a few words Press Ctrl + Z, then enter Step 8: Verify creation of the files Task: Display the contents of the “pcs” directory with the DIR command. type: dir Are the 3 sample files there (sample1, sample2, sample3)? ________________________ Step 9: File Attributes Files can have 4 different attributes, which determine their behaviour. In order to display the attribute(s) of a file, use the command attrib filename. R – Read Only file attribute – means a file can’t be changed A – Archive file attribute – used for backup purposes S – System file attribute – marks it as an important system file H – Hidden file attribute – hides the file from normal display Task: Display the file attributes of the sample files type: attrib What attributes do the files have? ________________________ Step 10: Changing File Attributes To change, or remove an attribute use the attrib [-/+] attribute_value filename command. The minus (-) option will remove an attribute value from a file and the plus (+) option will add an attribute value to a file. As discussed early, valid attribute values are R (read-only), A (archive), S (system), H (hidden). Task: Add the Read-Only attribute to the sample1.txt file type: attrib +R sample1.txt Task: add the archive attribute to the sample2.txt file type: attrib +A sample2.txt Task: Change the attribute value of the sample3.txt file to hidden type: attrib +H sample3.txt Task: Verify the file attributes of the files type: attrib Did the file attributes change (sample1 – R, sample2 – A, sample3 – H)? ______________________________ Task: Display your directory contents type: dir Is sample3.txt displayed? ______ Why not? ___________________ Task: Display Hidden Files – you can show hidden files with the /AH or /a switch type: dir /AH type: dir /a Is sample3.txt displayed? __________ What is the difference between these 2 commands? ________ Step 11: Managing Files: copy, ren, del Task: copy the sample2. file to the it directory, from the pcs directory type: copy c:\it\pcs\sample2.txt c:\it Notice that the original file location is listed 1st, and the new location is listed 2nd. Task: verify the file was copied: type: cd .. (you should now be in the it directory : c:\it) type: dir Is the sample2.txt file copied over? _______________________________ You can also use the copy command to make a 2 nd copy of a file, with a new name. Task: Make a backup of the sample2.txt file type: copy sample2.txt backup1.bak type: dir Are the new backup file and the original there? __________________ To rename a file, you can use the ren command Task: rename sample2.txt to new.txt type: ren sample21.txt new.txt type: dir Did the file get renamed? ___________ NOTE: At this point, you need to display your work to the instructor: cd\ cd it dir cd /pcs attrib (new.txt, backup1.bak) (sample1.txt, sample2.txt, sample3.txt) (sample1.txt – R, sample2.txt – A, samplet.txt – H) Step 12: Deleting files You can delete files in Dos by using the del command. Task: Delete sample1.txt file type: del sample1.txt Did the file delete? _____________ Why can you not delete it? _______ Task: Remove the Read-Only and hidden attributes type: attrib - R sample1.txt type: attrib –H sample3.txt Task: Delete sample1.txt file type: del sample1.txt Did the file delete? _____________ Step 13: Deleting multiple files If you want to delete all the files in a directory, you can use the command del *.* The * acts as a wildcard, which means delete any files starting with any letter and with any file extension, or delete all the files in this directory. Task: Delete all the files in the pcs directory Make sure you are currently inside the pcs directory before you continue – your prompt should look like this: c:\it\pcs type: del *.* Task: verify file deletion type: dir /a Are the files gone? _________ Step 14: Deleting Directories To delete a directory, you have to use the rd (remove directory command) and you must make sure that you are not currently inside the directory that you want to remove. If the directory has files inside of it, you must also delete those first. To back out of a directory, use the cd.. command to back up one level. Task: Back out of the pcs directory type: cd .. The command prompt should now show c:\IT Task: Delete the pcs directory type: rd pcs Did the folder delete? If it does not delete, go on to the next step Task: Delete all the files in the it directory Make sure you are currently inside the itdirectory before you continue – your prompt should look like this: c:\it type: del *.* Task: Back out of the IT directory and then remove it type: cd .. The command prompt should now show c:\ Task: Delete the it directory type: rd it Did the folder delete? If it does not delete, go on to the next step If your directories would not delete try this command: type cd\ to change to the c:\ drive type: deltree it type Y to confirm the removal of the it directory and all its subdirectories Task: verify directory removal type: dir /a Is the directory gone? _________