Working with the Command

Download Report

Transcript Working with the Command

Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Fourth Edition (Exam 220-802)
Working with the
Command-Line Interface
Chapter 9
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Overview
Fourth Edition (Exam 220-802)
• 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
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Historical/Conceptual
Fourth Edition (Exam 220-802)
• 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-OperatingSystem (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.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
220-802
Fourth Edition (Exam 220-802)
Deciphering the Command-Line
Interface
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Command-Line Interface (CLI)
Fourth Edition (Exam 220-802)
• How does a command-line interface
work?
– It begins with a prompt indicating the computer is
ready to do something (such as C:\>).
– The user types in a command and presses ENTER.
– The command is executed.
– A new prompt is displayed—ready for the next
command.
– CLI executes commands just as the Windows GUI
does.
• In CLI, you type the command and press ENTER.
• In GUI, you point and click to execute commands.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Fourth Edition (Exam 220-802)
Command-Line Interface
(continued)
Figure 1: Contents of C: directory from
the command line
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Figure 2: Contents of C: in Computer—
Icon view
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Fourth Edition (Exam 220-802)
Command-Line Interface
(continued)
Figure 4: Contents of C: in Computer—
Details view
Figure 3: Selecting Details view in
Computer
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Accessing the Command Line
Fourth Edition (Exam 220-802)
• Use the Run dialog box or Start Search
text box
– Start | Run
– Type cmd
(or)
– Type command
– Either runs the
Figure 5: Type cmd in the Run
cmd.exe executable
dialog box to open a command-line
program found in
interface window in Windows XP.
%systemroot%\system32
• You can also access the command line
through the Start | All Programs menu.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Fourth Edition (Exam 220-802)
Accessing the Command Line
(continued)
Figure 6: The command-line interface window with a C:\ prompt
Figure 7: The Windows Vista/7 command-line interface window
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
The Command Prompt
Fourth Edition (Exam 220-802)
• 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.
Figure 8: Command prompt indicating
focus on the C:\Diploma\APLUS\ folder
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Filenames and File Formats
Fourth Edition (Exam 220-802)
• Each program or piece of data is stored
as a file on the drive.
• Filenames have two parts:
– Filename
• In DOS, up to eight characters long
– Extension
• In DOS, up to three characters long
• Optional
• The filename and extension are
separated by a dot
– Called the 8.3 naming system
• These characters cannot be used today:
/\<>| :"*?
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Filenames and File Formats
Fourth Edition (Exam 220-802)
• Windows does not restrict the filename
to 8.3 (it 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)
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Fourth Edition (Exam 220-802)
Filenames and File Formats
(continued)
Figure 10: One file has no extension.
Figure 9: What kind of file is the one
on the lower right?
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
File Formats
Fourth Edition (Exam 220-802)
• All files are 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 eight-bit characters
• Unicode
– Uses 16-bit code to cover every character for the most
common languages
– First 256 characters are the ASCII characters
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
ASCII Character Chart
Fourth Edition (Exam 220-802)
Figure 11: ASCII characters
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Folders and Files
Fourth Edition (Exam 220-802)
• Folders and files must be unique.
– Can’t use 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
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Directory Tree
Fourth Edition (Exam 220-802)
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Fourth Edition (Exam 220-802)
Mastering Fundamental Commands
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Structure: Syntax and Switches
Fourth Edition (Exam 220-802)
• The command line requires the exact
syntax for each command.
• Type the name of the command and the
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.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Help
Fourth Edition (Exam 220-802)
• Help with any command is readily
available in one of three ways.
– HELP gives a one-line description of the command.
– HELP [command] gives specific help for the
command.
– [Command] /? gives specific help for the
command.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
dir Command
Fourth Edition (Exam 220-802)
• The dir command lists the contents of
a particular directory
– The dir /w command lists only the folder names
and filenames
Figure 12: Results for dir in a user’s folder
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
dir Command Switches
Fourth Edition (Exam 220-802)
Figure 13: Typing dir /? lists all possible switches for the dir command
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Directories: cd Command
Fourth Edition (Exam 220-802)
• 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:
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Making and Removing Directories
Fourth Edition (Exam 220-802)
• 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.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Fourth Edition (Exam 220-802)
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
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Running a Program
Fourth Edition (Exam 220-802)
• 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
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Running a Program (continued)
Fourth Edition (Exam 220-802)
Figure 15: Running mem in Windows
Vista 32-bit
Figure 14: The mem.exe program
displayed in the System32 folder
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Fourth Edition (Exam 220-802)
Working with Files
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Start at the Root
Fourth Edition (Exam 220-802)
• 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.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Working with Files
Fourth Edition (Exam 220-802)
• 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
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
attrib
Fourth Edition (Exam 220-802)
• 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.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Working with Files
Fourth Edition (Exam 220-802)
• 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
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Working with Files (continued)
Fourth Edition (Exam 220-802)
• ren is used to rename files.
• del and erase are used to delete files.
• copy is used to make a copy of the file in
a new location.
• move is used to move the file to a new
location.
• xcopy is used when working with
multiple directories.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Working with Files (continued)
Fourth Edition (Exam 220-802)
Figure 16: Rename failed me.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Figure 17: Success at last.
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Working with Files (continued)
Fourth Edition (Exam 220-802)
• robocopy is a newer command included
in Windows Vista and 7.
– Allows many different functions beyond copy and
xcopy
– Copies encrypted files
– Duplicates source directories
– Allows administrators to copy even when denied
permissions to files
– Resumes copying after an interruption
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Fourth Edition (Exam 220-802)
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 space.
C:\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.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Useful Utilities
Fourth Edition (Exam 220-802)
• 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.
• hostname
– Used to display the name of your computer, also
known as the hostname.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Useful Utilities (continued)
Fourth Edition (Exam 220-802)
Figure 18: The chkdsk /f /r utility and
switches on a locked drive
Figure 19: Using format /? at the command prompt
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Useful Utilities (continued)
Fourth Edition (Exam 220-802)
• sfc
– System File Checker helps restore Windows files
– sfc /scannow from a command prompt
Figure 20: Checking sfc options with sfc /? at a command prompt
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Fourth Edition (Exam 220-802)
Beyond A+
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
Using Special Keys
Fourth Edition (Exam 220-802)
• 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 and right) enable you to edit
commands.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
compact Command
Fourth Edition (Exam 220-802)
• compact
– Displays or alters the compression state of files
– compact /c
Figure 21: The compact command with no switches
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
compact Command (continued)
Fourth Edition (Exam 220-802)
Figure 23: The contents
of C:\compact have been
compressed.
Figure 22: Typing compact /c
compresses the contents of
the directory.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
compact Command (continued)
Fourth Edition (Exam 220-802)
Figure 24: Typing compact /u "Session 1.ppt"
decompresses only that file.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
cipher Command
Fourth Edition (Exam 220-802)
• 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.
Figure 25: Typing cipher /e /a encrypts the contents of the directory.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
cipher Command (continued)
Fourth Edition (Exam 220-802)
Figure 27: Typing cipher
/d /a dsc_4255.dng
decrypts only that file.
Figure 26: The cipher command
confirms that the files were encrypted.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
PowerShell
Fourth Edition (Exam 220-802)
• PowerShell
– Introduced in Windows XP and improved in
Windows 7.
– Powerful addition to traditional command-line
interface.
– Uses powerful tools called cmdlets.
– Syntax is slightly more complex than regular
command line use.
– In Windows 7, type powershell in search bar.
– In XP/Vista, you must download from Microsoft and
have the .NET 2.0 framework installed.
© 2013 The McGraw-Hill Companies, Inc. All rights reserved
Mike Meyers’ CompTIA A+®
Guide to 802:
Managing and
Troubleshooting PCs
PowerShell (continued)
Fourth Edition (Exam 220-802)
Figure 28: Simple commands in PowerShell
© 2013 The McGraw-Hill Companies, Inc. All rights reserved