LAB 11 - Intro to CLI

doc

School

Centennial College *

*We aren’t endorsed by this school

Course

101

Subject

Computer Science

Date

Dec 6, 2023

Type

doc

Pages

16

Uploaded by DeaconHippopotamus3887

Report
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: Objectives : After completing this lab, you will demonstrate the ability to: Use command-line functions and utilities to manage the operating system, including the proper syntax and switches. Use Notepad or Copy CON to create a file Move around a directory tree structure Parts needed: A computer with Windows 7, 10 or 11 Empty USB flash drive, or a USB flash drive with files that may be erased with no consequences. Ideally, it would be better to have at least 8 GB USB flash drive since these USB flash drives are more versatile than 4 GB or lower capacity USB flash drives. If you have more than one USB flash drive, one may be used as the working drive and the other to store any utilities or files you need. Notepad editor Notes: 1. For each step requiring a typed command the Enter key must be pressed to execute the DOS command. This instruction will not be given with each step. 2. For each command state your current directory and the full command. 3. Throughout this lab I will assume that the drive letter assigned to the USB flash drive will be E: If not, replace the correct drive letter wherever you see E: Convention: Boldface expressions indicate syntax that is entered literally as shown. Italic expressions indicate syntax for which you supply actual values. Vertical bar | indicates separate selections System administrators do not only use graphical user interface, or GUI, they use command-line interface as well since CLI is much more efficient and versatile. The steps to get to a command prompt are listed below for Windows 7, 10 or 11 operating systems. Click on Start | All Programs | Accessories | Command Prompt, or Click Start | type CMD in the Start Search box, and Enter Page 1 of 16
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: Windows 10/11 : In the Windows search box or Start button, type in CMD in the dialog box and click on or press Enter on Command Prompt. To pin the command prompt to the Taskbar or the Start Menu Click Start | Type CMD in the Start Search box | right-click CMD, and select Pin to Start Menu or Pin to the Task Bar. To run CMD as an Administrator Click Start | Type CMD in the Start Search box | right-click CMD, and click Run as an Administrator Using the Built-in doskey Program Doskey is built in to the command prompt and keeps history of all the commands you enter in the command prompt session. Using doskey you can retrieve previous commands so that you don’t have to type them again. The following table shows you the keys you can use to retrieve commands. Keyboard Key Description Up arrow Recall the previous command Down arrow Recalls the next command in the dos key if any Page up Recalls the oldest command in the current session Page down Recalls the most recent command in the current session You can use the following keys when editing a retrieved doskey command. Key or Key combination Description Left arrow Moves the cursor back on character at a time Right arrow Moves the cursor forward on character at a time CTRL + left arrow Moves the cursor back one word CTRL + right arrow Moves the cursor forward one word Home Moves the cursor to the beginning of the line End Moves the cursor to the end of the line Esc Clears the command from the display Cutting and Pasting to and from the Command Prompt The command prompt has two Edit Options, the Quick Edit Mode and the Insert Mode. You can choose to use none, one or both of the options. The Quick Edit Mode allows you to cut and paste from the command line, and the Insert Mode works just like the Insert key if the keyboard; it allows you to insert characters in the command line. Page 2 of 16
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: To access the Command Prompt properties: right-click on the Command Prompt title bar and select properties. You should see a figure similar to the one below. Figure 1 If Quick Edit Mode is enabled you can use the mouse to highlight text and press the Enter key to copy the highlighted text. To paste data, right-click in the command prompt window and the data is pasted. Note: CTRL+C and CTRL+V does not work. Getting Help with commands. Anytime you need some help with a particular command you can get help in two ways. 1. At the command prompt type help followed by the command in question 2. At the command prompt type the command followed by \? For example, if I needed help with the command DIR I can do it in the following ways: C:\> help dir C:\> dir /? Page 3 of 16
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: Boot into Windows 10 or 11. Using any of the methods described earlier, invoke the command prompt after Windows has loaded. 1. Does a prompt display? If not and you followed every step correctly, contact your professor. 2. What is the prompt displayed on the computer screen. Whatever is displayed is called the current directory. For example, if the prompt C:\Cencol> is displayed on the screen, C:\Cencol is the current directory. For every command you need to write down, make sure you include your current directory . 3. Changing from one drive to another . To change from one drive to another, all you do is type the drive letter followed by a colon (:). For example, to change from the C: drive to E: you would enter: C:\Documents and Settings\> E: and hit the Enter key. Insert your USB flash drive, use File Explorer and note the drive letter assigned to you USB flash drive. For the purposes of illustrating the examples in this lab document, let’s assume we use drive letter E: Change your current directory to the root directory of your USB flash drive. Enter the command you use to change to your USB flash drive in the space below: 4. Make Directory Use help and find out what is the use and syntax of the command MD (Make Directory). Execute the following command and explain what happened, assuming there is no pre-existing directory DIR1 or DIR2. E:\> MD DIR1\DIR2 Page 4 of 16
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: In the root directory of your USB flash drive, create a directory with your first name as the name of the directory. In the examples from this point and on, the directory name of “CNET101” is used but you need to use your own first name instead when you perform this lab. In this directory, create the necessary directories so that it will end up with the following directory tree, as shown in figure 2. Figure 2 5. Tree The command Tree displays the directories in a tree structure. If you need the command to display the files in addition to the directories, use the switch /f Type the command E:\> Tree Call your professor and show your directory tree. Professor’s initials: __________________ 6. Remove Directory The RD (Remove Directory) command is used to remove a directory. To remove a directory, the directory must be empty and you cannot remove a directory while your current directory is the directory you are trying to remove. Enter the following command: Page 5 of 16
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: E:\> RD Dir1 What is the response of your system? To remove DIR2, run the following command E:\> RD Dir1\Dir2 Remove Dir1. Enter the command you used in the space below. 7. Change Directory The Change Directory command CD command displays the name of the current directory when entered alone, or, changes your current directory to another when a path is given. Enter the command E:\> CD CNET101 What is your current directory? While in your new current directory type cd labs From the command prompt, type CD\ The prompt changes to E:\>. If a message appears stating invalid command or invalid directory, you made a typing error. If you suspect an error, verify the backslash is after CD with one blank space between them. The backslash starts from the left side and goes to the right (\). Other commands use a forward slash, which would be in the opposite direction (/). CD is the command for Change Directory, which tells the operating system to go to a different directory in the tree structure. The \ after the CD command tells the operating system to go to the root directory. An alternative way of typing this command is CD\. Notice the space between the CD command and the backslash. There are usually different ways to do every command from a prompt. Note that the CD\ command allows you to return to the root directory at any time. Execute the following command E:\> cd CNET101 \labs Now type E:\ CNET101\Labs> CD.. Page 6 of 16
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: What is your current directory now? The two periods ( ..) tell the operating system to move back (up) one level in the directory tree structure. Since you are three levels down (first level is the root, second is CNET101, and third is Labs), this command brings you back to the second level directory, which is CNET101. If you were to execute the same command again, it would have brought you one level up. In this case, this is the root directory. 8. DIR. The DIR command displays a list of files and subdirectories in a current directory. Change to C:\ and at the command prompt, type DIR. You should see something similar to the screen below. Figure 3 On the screen, you see a list of possible files and directories. Files are the items that show a filename and an extension, such as AUTOEXEC.BAT. A period (.) delimits the filename and the extension. Directories have a <DIR> entry, such as Program Files List one file and one directory, if any, that are shown on your screen. Page 7 of 16
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: When the number of files exceeds what can be shown on the screen, the files quickly scroll off the screen until all files finish displaying. The DIR command has a soft switch that controls this scrolling. A switch begins with a forward slash and enhances or changes the way a command performs. At the prompt, type CD \WINDOWS press enter and then type DIR How many files and how many directories are there in the Windows directory? Are they all visible? While still in the Windows directory type Dir /p After looking at the output on the screen, press Enter again. Continue pressing Enter until the prompt reappears. The DIR command’s /P switch tells the command to display the files one page at a time. At the prompt, type DIR /W . What is the function of the /W switch? Multiple switches can be used with a command. At the prompt, type DIR /W/P Using the DIR command /W and /P soft switches together cause the files to display in a wide list format as well as one page at a time. Type DIR m*.* The m *.* is not a switch. This “m” part of the command directs the operating system to list all files and subdirectories that start with the letter “m”. The * . * part means that all the files with whatever filename (following the letter m in this case) and all extensions with whatever extension name. The directory you chose may not have any files or subdirectories that start with the letter m. If this occurs, the operating system displays the message “File not found.” The * is known as a wildcard. A wildcard character substitutes for one or more characters. The first asterisk (*) is the wildcard for any name of a file. The second asterisk (*) is the Page 8 of 16
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: wildcard for any extension. Are any files or subdirectories that start with the letter m listed? If so, write one of them in the space below. If not, did the operating system let you know about this? If so, write the message displayed. Find out if the COMMAND.COM file is in the directory of drive C:\windows\system32. Make sure you use File Explorer to reveal hidden files (find out how to do this yourself). Which command did you use? Professor’s initials: __________________ 9. Using Notepad Exercise to Create Text Files and Batch Files Boot up your system if Windows isn’t loaded in yet. Insert the working USB flash drive into a USB port. What is the drive letter assigned to your USB flash drive? At the prompt type Notepad . When Notepad is launched, type the following text: Hello My name is “ your name here ” and I am a student in Centennial College . Click File | Save as Go to the directories and select the Labs directory in the CNET101 directory on Your USB flash drive. Save the file as Note1.txt. Create one more text file Chapter1.txt in the CNET101\Lectures directory. Type the following text: To obtain more information about commands, visit Page 9 of 16
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: P:\wwong02\CNET101 or in your CNET101 course shell 10. MOVE The file Chapter1.txt should be placed in E:\ CNET101\Lectures\chapters. Since we already have the file in E:\ CNET101\Lectures, you can MOVE the file to any directory. Execute the following command: E:\ CNET101> MOVE Lectures\chapter1.txt Lectures\chapters Can you delete the chapter1.txt from E:\ CNET101\Lectures? If yes, enter the command you would use in the space below. If not, why not? You will now create a Batch file. A batch file is an executable and a text file at the same time. It is an executable because you can run it and is text file because you can edit it. The contents of a batch file are commands. The extension of a batch file must always be .bat. Use notepad to create batch1.bat file in E:\ CNET101\Labs The contents of the batch file must contain the following commands C: CD c:\Windows Dir/p 11. Path When you want to run a command the most important thing is to tell the OS where to find the command. You can do this by giving the proper PATH. If you enter a path, the operating system will search just that path to find the command in question. If it finds it, it runs it, if it does not, it displays that the command is not recognized as an internal or external command, operable program or batch file. If you do not provide a path, the operating system will first check if the command is an internal command, like the DIR command. The internal commands are automatically loaded in memory during boot and therefor you do not need to provide a path. The OS will check memory and will find it. If it is not an internal command, it will then check to see if the command is in the current directory, and will run it if found or else will display the error message mentioned earlier. In the above exercise we created a batch file. The path to that batch file is: Page 10 of 16
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: E:\ CNET101\Labs. In other words, you tell the operating system to go to drive E:, then find the root directory (\), then in the root directory try find directory CNET101, then in CNET101 look for directory labs, and in there try to find the file to execute (Batch1.bat) Make the root of your USB drive become your current directory and execute the command: E:\> batch1.bat Did the batch file run? Why? Now run the command: E:\> CNET101\labs\batch1.bat In your own words, please explain why it run now and did not run before. Call your professor and show that the batch file runs. Professor’s initials: _____________________ 12. Type You can use the command TYPE to display the contents of a text file or a batch file. The syntax of the command is: TYPE [path] \ filename You have created a text file note1.txt. While your current directory is E:\, display the contents of note1.txt and then the contents of batch1.bat Write the full commands you used in the space below, including your current directory. Page 11 of 16
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: Page 12 of 16
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: 13. COPY If your system is not on, power on the computer and boot into Windows 10. When Windows loads, invoke the command prompt. Insert your USB flash drive. Assuming standard operating system installation, all of the commands cited below should reside in the C:\WINDOWS\SYSTEM32 directory Change to C: drive and then Type CD C:\WINDOWS\SYSTEM32 What is the purpose of the CD command? Type COPY FORMAT.COM E:\ CNET101 A message appears stating that one file copied. If the message does not appear, redo Steps 2 and 3. Since the prompt is currently at the proper directory, the full source path does not have to be typed. The destination is the E: drive’s root directory. Type COPY XCOPY.EXE E:\ CNET101 A message appears stating that one file copied. If the message does not appear; perform Step 4 again. Do a directory listing of the E: drive to verify the two files copied properly. List the command used to perform this step. If the files are not on the disk, redo the steps again. Use the COPY CON command to create a file called DEBUG.EXE in the System32 directory. What command would you use to copy this file, DEBUG.EXE, to the CNET101 directory on your USB flash drive if your current directory is C:\? In the E:\CNET101 create TEST1, TEST2 and TEST3 directories. Page 13 of 16
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: Type COPY E:\ CNET101\labs\*.* E:\ CNET101\TEST1\*.* What is the response of the system? Type e:\> COPY E:\ CNET101\lectures\*.* E :\ CNET101 \TEST2\*.* What is the response of the system? Why? 14. XCOPY XCOPY does whatever COPY does plus more by using soft switches. Execute the command: E:\ CNET101> xcopy/e E:\ CNET101 \lectures\*.* E:\ CNET101 \test2\*.* What is the response of the system? What is the use of switch /e? After you did all the steps of this lab, you should have a directory structured as shown in the figure below. Display your CNET101 directory structure and show it to your professor. Page 14 of 16
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: Figure 4 Professor’s initials: Review Questions 1. Change to drive C: From c:\> type the command to run the batch file batch1.bat , using just one command. Enter your command below. 2. While still your current directory being C:\>, enter the command to display the contents of the text file Note1.txt , again using a single command. Enter your command below. 3. Change your current directory to be e:\ CNET101\Labs. Type the command to run the batch file Batch1.bat 4. While still your current directory being e:\ CNET101\Labs, copy all directories and files from CNET101\test2 to directory Test3, using just one command Professor’s initials: ______________________ Page 15 of 16
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
CNET-101 L A B 11 PC Hardware Introduction to Command Line Interface Student name: Student ID: Station ID: Student Name/ID: Station ID: (0% will be entered as the lab grade if Student Name/ID or Station ID is missing) Date Due: Date Submitted: Student Signature: Note: ON THE DUE DATE RETURN ONLY THIS PAGE TO YOUR PROFESSOR FOR MARKING AND FOR SIGNING IN THE BOXES BELOW It is the student’s responsibility to have the professor sign all the steps stated in the lab. Failing to do so will result in the loss of marks. Check Points Professor’s Signature Date and Time Page # Step 5 9 11 14 Page 16 of 16