working with the command-line interface

40
© 2010 The McGraw-Hill Companies, Inc. All rights reserved Mike Meyers’ CompTIA A+ ® Guide to Managing and Troubleshooting PCs Third Edition Working with the Command-line Interface Chapter 15

Upload: ulric-stone

Post on 03-Jan-2016

48 views

Category:

Documents


0 download

DESCRIPTION

Working with the Command-line Interface. Chapter 15. Overview. In this chapter, you will learn how to Explain the operation of the command-line interface Execute fundamental commands from the command line Manipulate files and folders from the command line. Historical/Conceptual. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Working with the Command-line Interface

Chapter 15

Page 2: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Overview

• In this chapter, you will learn how to

– Explain the operation of the command-line interface

– Execute fundamental commands from the command line

– Manipulate files and folders from the command line

Page 3: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Historical/Conceptual

• IBM invented the PC in the late ’70s but needed an operating system– Digital Research had an OS but turned them down– IBM went to a small company (Bill Gates at

Microsoft) that had created BASIC– Microsoft had never written an OS but accepted

the challenge• Gates found an OS called Quick-and-Dirty-Operating-

System (QDOS) and purchased it from the person who wrote it

• Microsoft released it as MS-DOS V 1.1 (Microsoft Disk Operating System)

• MS-DOS 6.22 ultimately released in 1994• DOS used a command-line interface

Page 4: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Deciphering the Command-line Interface

Practical Application

Page 5: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Command-line Interface (CLI)

• How does a command-line interface work?– Begins with a prompt indicating the computer is

ready to do something (such as C:\>)

– Type in a command and press ENTER

– The command is executed

– A new prompt is displayed—ready for the next command

– CLI executes commands like the Windows GUI• In CLI, type the command and press ENTER• In GUI, point and click to execute commands

Page 6: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Accessing the Command Line

• Use the Run dialog box or Start Search text box– Start | Run– Type cmd

(or)– Type command– Either runs the

cmd.exe executable program found in %systemroot%\system32

• You may also access the command line through the Start | All Programs menu

Page 7: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

The Command Prompt

• The command prompt is always focused on a specific folder– Commands operate on the files and folders in the

folder on which the command line is focused– You can first focus on the drive and folder where

you want to work to make commands simpler

Page 8: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Filenames and File Formats

• Each program or piece of data is stored as a file on the drive

• Filenames have two parts– Filename

• In DOS, up to 8 characters long– Extension

• In DOS, up to 3 characters long• Optional

• The filename and extension are separated by a dot– Called the 8.3 naming system

• These characters may not be used today/ \ < > | : " * ?

Page 9: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Filenames and Formats

• Windows does not restrict the filename to 8.3 (can be up to 255 characters)– To be backward-compatible with DOS you need to

follow the 8.3 standard– Windows creates two filenames for every file to

ensure backward-compatibility

• The extension tells the computer the type of file– .exe, .doc, .xls– .gif, .jpg, .png– .chm (help file)

Page 10: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

File Formats

• All files written in binary format– Different programs have unique methods of reading and

writing, so one program may or may not understand files from another program.

– Need for a universal format

• American Standard Code for Information Interchange (ASCII) used for text– First universal file format– Defines 256 8-bit characters

• Unicode– Uses 16-bit code to cover every character for the most

common languages– First 256 characters are the ASCII characters

Page 11: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

ASCII Character Chart

Page 12: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Folders and Files

• Folders and files must be unique– Can’t be the same name in the same folder

• C:\ represents the root directory of C

• To describe a subfolder, add the name of the folder– C:\TEST

• The location of a file is called the path– The path of C:\test\file.txt is C:\test

Page 13: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Directory Tree

Page 14: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Mastering Fundamental Commands

Page 15: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Structure: Syntax and Switches

• The command line requires the exact syntax for each command

• Type the name of the command and desired or allowed switches, and then press ENTER to execute the command– Switches modify the behavior of the command– Multiple switches may be allowable– DIR /W /P

displays the directory in wide mode and one page at a time

Page 16: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Help

• Help with any command is readily available in one of three ways– HELP gives a one-line description of each

command– HELP [command] gives specific help for the

command– [Command] /? gives specific help for the command

Page 17: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

DIR Command

• The DIR command lists the contents of a particular directory– The DIR /W command lists only the folder and file

names

Page 18: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

DIR Command Switches

Page 19: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Directories: CD Command

• The CD (or CHDIR) command is used to change the focus to a different directory

• The CD\ command is used to return to the root directory

• Type CD [folder name] and then press ENTER to change focus to that folder or directory

• Type CD .. and press ENTER to go up one directory

• To switch between drives, type the drive letter followed by a colon, and then press ENTER– C:– D:

Page 20: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Making and Removing Directories

• The MD (or MKDIR) command is used for creating a directory

• The DEL command is used for deleting files, and the RD (RMDIR) command is used for deleting directories and subdirectories

• RD /S will removed populated folders and their contents

Page 21: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Lab – Making and Removing Folders

1. Change focus to root

2. Create three folders– class– docs– backup

3. Create a subfolder in backup– temp

4. Delete RD the temp folder

5. Use DIR to check each step

Page 22: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Running a Program

• To run a program– Change the prompt focus to the directory where

the program is stored cd c:\windows\system32

– Type the filename with or without its extension and press ENTER

edit.com

Page 23: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

EDIT

• EDIT is a command-line command that starts a basic text editor

Page 24: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Working with Files

Page 25: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Start at the Root

• What's in your root directory?

• Double-click C: drive in My Computer– Hey! Where are the Windows system files, like

NTLDR and BOOT.INI?– Could go to Folder Options and display hidden and

system files, or could go to the prompt

• DIR /P still doesn't show the system files, so we need a new tool

Page 26: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Working with Files

• Attributes (H, R, S, A) are special values assigned to a file– Hidden: hides the file– Read-only: protects a file

from being deleted or modified– System: identifies system files– Archive: identifies files that

have not been backed up

• The ATTRIB.EXE program is used to inspect and change file attributes

Page 27: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

ATTRIB

• ATTRIB can be used to change the attributes

– Use + to add attribute– Use – to remove attribute

ATTRIB +R AILOG.TXT Makes the file read only

ATTRIB –H AILOG.TXT Makes the file no longer hidden

Page 28: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Working with Files

• Wildcards– Wildcards are special characters that enable

commands to act on more than one file at a time– The * represents any number of characters– The ? represents a single character

DIR *.TXT Lists all files that end in .TXT

DIR *.?XT Lists all files that end in XT

Page 29: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Working with Files (continued)

• REN command is used to rename files

• DEL and ERASE commands are used to delete files

• COPY command is used for making a copy of the file in a new location

• MOVE command is used for moving the file to a new location

• XCOPY command is used for working with multiple directories

Page 30: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Lab – Create, Copy, Move

1. Use EDIT to create two text files in the \docs folder

2. Use COPY to copy both to the \backup folder

3. Use MOVE to move both to \class folder

4. Use DIR to verify each step

Page 31: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Mike’s Five-Step COPY/MOVE Process

1. Point the command prompt to the directory containing the files to be copied or moved

C:\>CD \DOCS

2. Type COPY or MOVE and a spaceC:\DOCS>COPY

3. Type the name(s) of the file(s) to be copied/moved and a space

C:\DOCS>COPY *.doc

4. Type the path of the new location for the files

C:\DOCS>COPY *.doc c:\Steam

5. Press ENTER

Page 32: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Working with Batch Files

• Batch files are text files that store a series of commands– One command on each line– Batch files use the .BAT extension– Batch files may be edited with any text editor

• Notepad• EDIT

– Batch files get their own type of icon

Page 33: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Lab – Creating a Batch File

1. Get to the root directory and type EDIT to run Edit

2. Using EDIT, type in some commands on their own lines, like this– md greatbook– cd greatbook

3. Save the file with a .BAT extension– C:\test.bat

4. From the command prompt, run the batch file– C:\>Test.bat

Page 34: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Lab – Batch Rename

1. Using EDIT, create a batch file in \class folder– Contents should be

• REN *.TXT *.NICE

– Save as• REN.BAT

2. Use DIR to verify that contents of the \class folder have .TXT extensions

3. Run batch file

4. Use DIR to verify that the file extensions have changed

Page 35: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Useful Utilities

• CHKDSK (/f /r)– Runs the command-line version of error-checking– Run to recover from accidental shutdown, such as

during a disk defragmentation

• FORMAT– Normally done from the GUI, but can do this quickly

from the CLI– FORMAT X: /q is a great way to wipe a drive

• SFC– System File Checker helps restore Windows files– SFC /scannow from a command prompt

Page 36: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Beyond A+

Page 37: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

Using Special Keys

• F1 function key brings back the previous command one letter at a time

• F3 function key brings back the entire command at once

• Arrow keys– You can also use the arrow keys (up and down) to

scroll through commands– Arrow keys (left to right) enable you to edit

commands

Page 38: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

COMPACT Command

• COMPACT– Displays or alters the compression state of files– compact /c

Page 39: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition

CIPHER Command

• CIPHER– Displays or alters the encryption state of files– /e specifies encryption operation– /a says to apply it to the files as well as the

directory

Page 40: Working with the  Command-line Interface

© 2010 The McGraw-Hill Companies, Inc. All rights reserved

Mike Meyers’ CompTIA A+® Guide to

Managing and Troubleshooting PCs

Third Edition