Chapter 14 Working with the Command- Line Interface MELJUN CORTES MELJUN CORTES
Chapter 14Working with the Command-
Line Interface
MELJUN CORTESMELJUN CORTES
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
OverviewIn this chapter, you will learn to
Explain the operation of the command-line interface
Execute fundamental commands from the command line
Manipulate files and folders from the command line
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Historical/ConceptualIBM invented the PC in the late ’70s but needed
an operating systemDigital Research had an OS but turned them downIBM went to a small company (Bill Gates at
Microsoft) that had created BASICMicrosoft had never written an OS but accepted
the challengeGates 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 1994DOS used a command-line interface
Deciphering the Command-Line Interface
IT Technician
CompTIA A+Technician
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Command-Line Interface (CLI)
How does a command-line interface work?Begins with a prompt indicating the computer is
ready to do somethingType in a command and press ENTERThe command is executedA new prompt is displayed—ready for the next
commandCLI executes commands like the Windows GUI
In CLI, type the command and press ENTERIn GUI, point and click to execute commands
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Accessing the Command LineIn Windows 2000 use the Run dialog box
Start | RunType cmd
You may also access the command line through the Start | All Programs menu
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
The Command PromptThe command prompt is always focused on
a specific folderAny commands operate on the files and
folders in the folder in which you are focusedYou must first focus on the drive and folder
where you want to work
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Filenames and File FormatsEach program or piece of data is stored as a
file on the driveFilenames have two parts
FilenameIn DOS, up to 8 characters long
ExtensionIn DOS, up to 3 characters longOptional
The filename and extension are separated by a dotCalled the 8.3 naming system
These characters may not be used/ \ [ ] | ÷ + = ; , * ?
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Filenames and FormatsWindows does not restrict the filename to
8.3 (can be up 255 characters)To be backward-compatible with DOS you
need to follow the 8.3 standardWindows creates two filenames for every file
to ensure backward-compatibility
The extension tells the computer the type of file.exe, .doc, .xls
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
File FormatsAll files written in binary format
American Standard Code for Information Interchange (ASCII) used for textUniversal file formatDefines 256 8-bit characters
UnicodeUses 16-bit code to cover every character for
the most common languages
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
ASCII Character Chart
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Drives and FoldersAt boot, Windows assigns partitions and a
drive letterFloppy drives are usually assigned A: or B:Hard drive partitions may be assigned C: to Z:CD-ROM drives are named after hard drives
Windows uses a hierarchical directory treeFiles are put into groups called folders
In DOS we call folders directoriesThe root directory is at the beginning of the
hierarchical structure with folders underneath
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Folders and FilesFolders 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 folderC:\TEST
The location of a file is called the pathThe path of C:\test\file.txt is C:\test
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Directory Tree
Mastering Fundamental Commands
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Structure: Syntax and SwitchesThe command line requires the exact syntax for
each command
Type the name of the command and desired or allowed switches
Switches modify the behavior of the commandMultiple switches may be allowable
DIR /W /PDisplays the directory in wide mode and one page at a time
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Help
Help with any command is readily available in one of three waysHELP gives a one-line description of each
commandHELP command gives specific help for the
commandCommand /? gives specific help for the
command
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
DIR Command The DIR command lists the contents of a
particular directoryThe DIR/W command lists only the filenames
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
DIR Command Switches
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
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
CD .. Goes up one directory
To switch between drives, type the drive letter followed by a colonC:D:
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
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
The DELTREE command is used for deleting directories containing files and subdirectories
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Running a Program To run a program:
Change the DOS focus to the directory where the program is stored
CD C:\Program Files\My Program
Type the filename with or without its extension and press ENTER
Setup.exe
Working with Files
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Working with Files Attributes (H, R, S, A) are special values
assigned to a fileHidden: hides the fileRead-only: protects a file
from being deleted or modifiedSystem: identifies system filesArchive: identifies files that
have not been backed up
The ATTRIB.EXE program is used to inspect and change file attributes
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
AttribAttrib can be used to change the attributes
Use + to add attribute- Use – to remove attribute
Attrib +R AILOG.TXT Makes it read only
Attrib –H AILOG.TXT Makes it no longer hidden
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
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 charactersThe ? represents a single character
DIR *.TXT Lists all files that end in .TXTDIR *.?XT Lists all files that end in XT
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Working with Files REN command is used to rename filesDEL and ERASE commands are used to delete
filesCOPY command is used for making a copy of
the file in a new locationMOVE command is used for moving the file to
a new locationXCOPY command is used for working with
multiple directories
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Mike’s Five-Step COPY/MOVE Process1. Point the command prompt to the directory
containing the files to be copied or movedC:\> 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:\Steam5. Press ENTER
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Working with Batch FilesBatch files are text files that store a series
of commandsOne command on each lineBatch files use the .BAT extensionBatch files may be edited with any text editor
NotepadEDIT
Batch files get their own type of icon
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
EDITEDIT is a command-line command that
starts a basic text editor
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Creating a Batch FileUsing EDIT, type in some commands on
their own line (such as cd:\ and Dir)
Save the file with a .BAT extensionC:\test.bat
Launch a command prompt and run the batch fileC:\> CD \C:\> Test.bat
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
Additional CommandsSome additional commands are
VER shows the current version of Windows
ECHO tells the batch file to put text on the screen
TYPE displays the contents of a batch file on the screen
SET display settings that Windows has loaded by default
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
ECHO CommandECHO will display text on the screen
ECHO OFF turns off the display of text on the screen
@ at the beginning of a line prevents displaying the command, but not the result of the command
@ECHO OFF is frequently used in batch files to “clean up” the appearance when the batch file is run
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
SET and PATH CommandsSET will display the list of settings that
Windows loads by default
Programs (and batch files) are run from the location where the prompt isIf the program is not located in the current
folder, you receive an error messageTo tell your command to look in other places,
use the PATH commandPATH by itself lists the current list of places to look for
a programPATH= location; location; location; … will add locations
Beyond A+
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
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
The DOSKEY command stores a list of all previously typed commands and can be accessed by using the up arrow keyType DOSKEYWindows XP/2000 automatically starts the program
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
COMPACT CommandCOMPACT
Displays or alters the compression state of files
compact /c
© 2007 The McGraw-Hill Companies, Inc. All rights reserved
CIPHER CommandCIPHER
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
© 2007 The McGraw-Hill Companies, Inc. All rights reserved