Last Updated on November 1, 2018 by InfraExam
22.214.171.124 Lab – Common Windows CLI Commands Answers
Lab – Common Windows CLI Commands (Answers Version)
In this lab, you will use CLI commands to manage files and folders in Windows.
- 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.
- Log on to a computer as a user with administrative privileges. The account ITEUser is used as the example user account throughout this lab.
- 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 /?.
- At the command prompt, type help and press Enter. A list of commands is displayed.
- 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.
- Type md /? at the prompt to display additional information and switches that can be used with this command.
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.
- Type cd at the command prompt. What is the current directory?____________________________________________________________________________________
Answers may vary. The current directory is C:\Users\ITEUser in this example.
- Type dir at the command prompt to list the files and folders that are in the current folder.
- 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.
- Type dir to verify the folders have been created.
- 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.
- Within the ITEfolder3 folder, create a folder named ITEfolder4. Use the dir command to verify the folder creation.
- 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?____________________________________________________________________________________
- What would be the current directory if you issue this command at C:\Users\ITEfolder3?____________________________________________________________________________________
Step 4: Create text files.
- Navigate to the C:\Users\ITEUser\ITEfolder1 directory. Type cd ITEfolder1 at the prompt.
- 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.
- Use the dir command to verify the files are in the ITEfolder1 folder.
Step 5: Copy, delete, and move files.
- 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.
- Type dir at the prompt to verify that doc2.txt is no longer in the current directory.
- Type cd C:\Users\ITEUser\ITEfolder2 to change the directory to ITEfolder2. Type dir at the prompt to verify doc2.txt has been moved.
- 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.
- Now use the move command to move doc2_copy.txt to ITEfolder1. Type move doc2_copy.txt ..\ITEfolder1.
- 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.
- Type dir ..\ITEfolder1 to view the content in ITEfolder1 without leaving the current directory.
- Change the current directory to ITEfolder1. Type cd ..\ITEfolder1 at the prompt.
- 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.
- 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.
- Verify the content of ITEfolder3. Type dir ..\ITEfolder3.
- Verify the content in ITEfolder1. Move all the files in this folder to ITEfolder2. Type move doc*.txt ..\ITEfolder2 to move the files.
- 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.
- 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.
- Use help xcopy to determine which switch would allow the xcopy command to copy all the files and directories.
- 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.
- 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.
- Navigate to the C:\Users\ITEUser\ITEfolder3 directory.
- Use the rd ITEfolder4 to delete the empty directory. Verify the directory removal using the dir command.
- Navigate to C:\Users\ITEUser folder.
- Use the rd ITEfolder2 to delete the non-empty directory. The message indicates that the directory is not empty and cannot be deleted.
- Use rd /? command to determine the switch that allows the deletion of a non-empty directory.
- Type rd /S ITEfolder2 to delete this folder. When prompted, type y to delete the directory. Use dir to verify that ITEfolder2 was deleted.
- Type exit to close the command prompt window.
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.