6.1.5.4 Lab – Common Windows CLI Commands Answers

6.1.5.4 Lab – Common Windows CLI Commands Answers

Lab – Common Windows CLI Commands (Answers Version)

Introduction

In this lab, you will use CLI commands to manage files and folders in Windows.

Recommended Equipment

  • A computer running Windows

Answers Note: The students can complete this lab from any of the four Windows operating systems. Also, students may need to change the example directory letter C if a different letter is used on the lab computers.

Step 1: Access the Windows command prompt.

  1. Log on to a computer as a user with administrative privileges. The account ITEUser is used as the example user account throughout this lab.
  2. To access the Windows command prompt in Windows 8, navigate to the Start screen and type Command Prompt. Click Command Prompt.
    In Windows 7, click Start and type Command Prompt in the Search programs and files field. Click Command Prompt to continue.
    In Windows Vista, click Start and type Command Prompt in the Start Search field. Click Command Prompt to continue.

Step 2: Display command help from the command prompt.

You can display command line help using the help command. For more information on a specific command, type the command followed by /?.

  1. At the command prompt, type help and press Enter. A list of commands is displayed.
    6.1.5.4 Lab – Common Windows CLI Commands Answers 01

    6.1.5.4 Lab – Common Windows CLI Commands Answers 01

    • Using the information displayed by the help command, explain the functions of the following commands:
    Command Function
    CD Displays the name of or changes the current directory.
    CHKDSK Checks a disk and displays a status report.
    COPY Copies one or more files to another location.
    DEL Deletes one or more files.
    DIR Displays a list of files and subdirectories in a directory.
    DISKPART Displays or configures Disk Partition properties.
    EXIT Quits the CMD.EXE program.
    FORMAT Formats a disk for use with Windows.
    GPRESULT Displays Group Policy information for machine or user.
    MD Creates a directory.
    TASKLIST Display all currently running tasks including services.
    RD Removes a directory
    ROBOCOPY (Note, this command only works in Windows 7 and Vista): Advanced utility to copy files and directory trees.
    SHUTDOWN Allows proper local or remote shutdown of machine.
    XCOPY Copies files and directory trees.
  2. Type md /? at the prompt to display additional information and switches that can be used with this command.

    6.1.5.4 Lab – Common Windows CLI Commands Answers 02

    6.1.5.4 Lab – Common Windows CLI Commands Answers 02

Step 3: Create and change directories.

In this step, you will use the change directory (cd), make directory (md), and directory (dir) commands.

Note: A directory is another word for folder. Directory and folder are used interchangeably throughout this lab.

  1. Type cd at the command prompt. What is the current directory?____________________________________________________________________________________
    Answers may vary. The current directory is C:\Users\ITEUser in this example.
  2. Type dir at the command prompt to list the files and folders that are in the current folder.

    6.1.5.4 Lab – Common Windows CLI Commands Answers 03

    6.1.5.4 Lab – Common Windows CLI Commands Answers 03

  3. In the current directory, use the md command to create three new folders: ITEfolder1, ITEfolder2, and ITEfolder3. Type md ITEfolder1 and press Enter. Create ITEfolder2 and ITEfolder3.

    6.1.5.4 Lab – Common Windows CLI Commands Answers 04

    6.1.5.4 Lab – Common Windows CLI Commands Answers 04

  4. Type dir to verify the folders have been created.
  5. Type cd ITEfolder3 at the command prompt and press Enter. Which folder are you in now?____________________________________________________________________________________
    Answers may vary. The current directory is C:\Users\ITEUser\ITEfolder3 in this example.
  6. Within the ITEfolder3 folder, create a folder named ITEfolder4. Use the dir command to verify the folder creation.
  7. Type cd .. to change the current directory. Each .. is a shortcut to move up one level in the directory tree.
    After issuing the cd .. command, what is your directory now?____________________________________________________________________________________
    C:\Users\ITEUser
  8. What would be the current directory if you issue this command at C:\Users\ITEfolder3?____________________________________________________________________________________
    C:\Users

Step 4: Create text files.

  1. Navigate to the C:\Users\ITEUser\ITEfolder1 directory. Type cd ITEfolder1 at the prompt.
  2. Type echo This is doc1.txt > doc1.txt at the command prompt. The echo command is used to display a message at the command prompt. The > is used to redirect the message from the screen to a file. For example, in the first line, the message This is doc1.txt is redirected into a new file named doc1.txt. Use the echo command and > redirect to create these files: doc2.txt, file1.txt, and file2.txt.

    6.1.5.4 Lab – Common Windows CLI Commands Answers 05

    6.1.5.4 Lab – Common Windows CLI Commands Answers 05

  3. Use the dir command to verify the files are in the ITEfolder1 folder.

    6.1.5.4 Lab – Common Windows CLI Commands Answers 06

    6.1.5.4 Lab – Common Windows CLI Commands Answers 06

Step 5: Copy, delete, and move files.

  1. At the command prompt, type move doc2.txt C:\Users\ITEUser\ITEfolder2 to move the file doc2.txt to the C:\Users\ITEUser\ITEfolder2 directory.

    6.1.5.4 Lab – Common Windows CLI Commands Answers 07

    6.1.5.4 Lab – Common Windows CLI Commands Answers 07

  2. Type dir at the prompt to verify that doc2.txt is no longer in the current directory.

    6.1.5.4 Lab – Common Windows CLI Commands Answers 08

    6.1.5.4 Lab – Common Windows CLI Commands Answers 08

  3. Type cd C:\Users\ITEUser\ITEfolder2 to change the directory to ITEfolder2. Type dir at the prompt to verify doc2.txt has been moved.

    6.1.5.4 Lab – Common Windows CLI Commands Answers 09

    6.1.5.4 Lab – Common Windows CLI Commands Answers 09

  4. Type copy doc2.txt doc2_copy.txt to create a copy of doc2.txt. Type dir at the prompt to verify a copy of the file has been created.
  5. Now use the move command to move doc2_copy.txt to ITEfolder1. Type move doc2_copy.txt ..\ITEfolder1.
  6. A copy of doc2.txt can be created and renamed with the copy command. Type copy doc2.txt ..\ITEfolder1\doc2_new.txt at the prompt.
  7. Type dir ..\ITEfolder1 to view the content in ITEfolder1 without leaving the current directory.
  8. Change the current directory to ITEfolder1. Type cd ..\ITEfolder1 at the prompt.
  9. Move file1.txt and file2.txt into ITEfolder3. To move all the files that contain the word file into ITEfolder3 with one command, use a wildcard (*) character to represent one or more characters. Type move file*.txt ..\ITEfolder3.
  10. Now delete doc2_copy.txt from the ITEfolder1 directory. Type del doc2_copy.txt. Use the dir command to verify the file deletion.

Step 6: Use the xcopy command.

In this step, the xcopy command is used to copy all the content in a directory and delete the empty directory.

  1. Verify the content of ITEfolder3. Type dir ..\ITEfolder3.
  2. Verify the content in ITEfolder1. Move all the files in this folder to ITEfolder2. Type move doc*.txt ..\ITEfolder2 to move the files.
  3. Type xcopy ..\ITEfolder3 . at the prompt to copy the content of ITEfolder3 to ITEfolder1. Note the . at the end of the command. It is a shortcut for the current directory.
  4. At the prompt, type dir to display the content of ITEfolder1. Only the files in the ITEfolder3 were copied into ITEfolder1. The directory ITEfolder4 was not copied into ITEfolder3.
  5. Use help xcopy to determine which switch would allow the xcopy command to copy all the files and directories.
  6. Because ITEfolder4 is an empty folder, /E is needed to copy all the content of ITEfolder3 and the empty subfolder.
    Type xcopy /E ..\ITEfolder3 . at the prompt to copy the files. When prompted, type a to allow overwriting the existing files.
  7. Verify the ITEfolder4 was also copied in ITEfolder1.

Step 7: Delete directories.

In this step, you will delete an empty and a non-empty directory using the rd command.

  1. Navigate to the C:\Users\ITEUser\ITEfolder3 directory.
  2. Use the rd ITEfolder4 to delete the empty directory. Verify the directory removal using the dir command.
  3. Navigate to C:\Users\ITEUser folder.
  4. Use the rd ITEfolder2 to delete the non-empty directory. The message indicates that the directory is not empty and cannot be deleted.
  5. Use rd /? command to determine the switch that allows the deletion of a non-empty directory.
  6. Type rd /S ITEfolder2 to delete this folder. When prompted, type y to delete the directory. Use dir to verify that ITEfolder2 was deleted.
  7. Type exit to close the command prompt window.

Reflection

What are the advantages of using CLI vs. GUI?

_______________________________________________________________________________________

_______________________________________________________________________________________

Answers may vary. For example, the commands in the CLI in Windows have not changed in the different Windows versions. The GUI interfaces in different Windows versions have changed dramatically.

Leave a comment