Chapter 5: Command Prompt Procedures

Exam Objectives

check.png Identifying the fundamentals of using command line utilities to manage Windows

check.png Using command line tools to manage directories and files

In this chapter, you take a look at several command prompt utilities and a few graphical utilities. Even in the age of Windows, statements that can be issued from a command prompt are still required knowledge for support professionals. This knowledge will help you automate processes — such as batch files — and solve problems when the graphical operating system is not functioning. After reading this chapter, you should have a good understanding of many of the basic commands that are available from the command prompt.

As an added benefit, you find out how to build a basic batch file with some controls in it. I put this information at the end of the chapter because you won’t be tested directly on that knowledge, but it will sure come in handy on the job.

As an A+ Certified Professional, you will want to use the full range of tools available to you. This chapter introduces you to many of the command line tools that allow you to quickly diagnose and repair problems with operating systems.

fortheexam.eps The exam objectives call for testing on command line tools, which might not be limited to just the common tools listed in this book. To review new command line tools, choose Start⇒Help and Support and search for New Command-line Tools. To review all possible command line tools, choose Start⇒Help and Support and search for Command-line reference A-Z.

Using command.com and cmd.exe

Many of the really useful utilities in Windows are command line–based. Windows Vista and earlier OSes give you two options for running command line utilities: command.com and cmd.exe.

When working with MS-DOS and Windows 9x, the file command.com is the command line interpreter, and it serves as the basic method of executing programs in the OS. Some programs that were executed were programs internal to command.com, but others were external and could be found on the hard drive.

Windows NT–based OSes, such as Windows XP and Windows Vista, use cmd.exe as the basic command line interpreter for issuing commands. When using cmd.exe, you are using a Windows 32-bit application from the point of view of memory management and application stability. command.com still exists on these OSes, but it exists for backward compatibility for older applications.

Typically, when you want to use a command prompt within Windows, you should run cmd.exe by choosing Start⇒Run, typing cmd.exe, and clicking OK. cmd.exe can also be found from the Start menu under All Programs⇒Accessories⇒Command Prompt. This runs as a 32-bit Windows application and thereby can spawn other applications or support standard memory management. Each copy of cmd.exe that you execute appears on the process list in Task Manager. If you run cmd.exe, the first two lines tell you what executed. Here is an example of what Windows 7 shows:

Microsoft Windows [Version 6.1.7600]

Copyright (c) 2009 Microsoft Corporation. All rights reserved.

command.com on the other hand, is a 16-bit MS-DOS application. It loads a simulated 16-bit environment in the form of ntvdm.exe (NT Virtual DOS Machine; NTVDM). You will see ntvdm.exe listed on the Process tab of Task Manager. The first two lines listed in this window are

Microsoft(R) Windows DOS

(C)Copyright Microsoft Corp 1990-2001.

You will notice that, in this case, you are running DOS and Windows 7 (Windows Version 6.1). You will also notice, if you are running an OS prior to Windows Vista, that your long filenames are no longer supported. If you use the command prompt to launch other 16-bit Windows applications, they will be launched within the NTVDM that is executing. The NTVDM is the environment that all 16-bit MS-DOS applications and 16-bit Windows applications run in. For more information about supporting these applications, refer to Book VI, Chapter 2.

cmd.exe is used when running all other applications. As I mention earlier, it is a 32-bit command prompt with a number of enhancements, including

diamonds.jpg The ability to run 16-bit and 32-bit command line utilities

diamonds.jpg The ability to run POSIX (Portable Operating System Interface for Unix) and OS applications

diamonds.jpg Built-in DOSKey support for saving and executing commands

fortheexam.eps Windows XP and Windows Vista use cmd.exe as the main command line interface and provide command.com for backward compatibility. Remember that command.com is not supported on 64-bit Windows operating systems.

Managing Directories

All files that are saved to disk are stored in a hierarchical directory structure. All the files could be placed at the top of this structure, but it would be disorganized, and therefore poorly managed. Also, most top-level directories, or root directories, can hold a limited number of files. This directory structure can hold as many nested subdirectories as you want. The commands discussed in the following sections allow you to get listings of files as well as create and delete directories on your disk.

fortheexam.eps All command line tools in this section have not changed substantially since MS-DOS.

dir

The first command that you will see is the directory command (dir). This command is used to get a listing of the files that are in a directory on your disk. Using dir by itself gives you the listing of your current directory. The current directory is usually listed in the command prompt, like this:

C:WINDOWS>_

The dir command is very useful and has several options, discussed later in this section. First, though, you need a firm grasp of wildcards, relative paths, and absolute paths.

Wildcards

Two wildcards can be used to modify what results you receive: * and ?. These can be used multiple times in different combinations in the same command to filter the results.

The * wildcard represents one or more characters. Here is an example of using the * wildcard to retrieve a list of files that match a certain pattern. The command

dir WIN*.*XE

returns the following:

WINMINE.EXE

WINHELP.EXE

WINHLP32.EXE

WININIT.EXE

WINVER.EXE

WINFILE.EXE

WINPOPUP.EXE

WINIPCFG.EXE

WINREP.EXE

The results include all files that start with win and end with xe, with any number of characters in between — even zero. These wildcards are also useful when used in conjunction with copy commands, which I discuss later in the chapter.

The ? wildcard character works a little different than * because ? represents one or zero characters. Here is an example of ? in action, as it looks for all files that were created on the fifth of any month after Jan 01, 2000, given that all the filenames match their dates using eight-character numeric dates with the pattern of mmddyyyy.txt. The command

dir ??052???.TXT

would return the following list of files:

01052000.TXT

05052000.TXT

10052000.TXT

11052000.TXT

12052000.TXT

04052002.TXT

12052003.TXT

06052008.TXT

The ? in the command doesn’t return any files that have more than two characters before the 05 and doesn’t return any more than three characters after the 2 in the dir statement.

Relative paths and absolute paths

When you use dir, you are given a directory listing for your current directory. To see the listing for a different directory, Table 5-1 provides several options for choosing a different directory. All the command examples in the table use this directory structure:

c:parent_dirchild_dirgrandchild_dir

with the current directory set to c:parent_dirchild_dir.

Table 5-1 Ways to Specify Directory Paths

Command

Directory Result

dir

Returns the listing for the current directory c:parent_dirchild_dir.

dir c:

Returns the listing for the current directory on the C drive c:parent_dirchild_dir.

dir c:parent_dir

Returns the listing for c:parent_dir.

dir

Returns the listing for the root of the current drive c:.

dir ..

Returns the listing for the parent directory of the current directory c:parent_dir.

dir ....

Returns the listing of the parent directory of the parent directory of the current directory c:.

dir ..child_dir

Returns the listing of a directory named child_dir, which is a child of the parent directory c:parent_dirchild_dir.

dir grandchild_dir

Returns the listing of a child directory named grandchild_dirc:parent_dirchild_dirgrandchild_dir.

Whenever a full path is specified, starting with the drive letter, it is referred to as an absolute path. If you do not specify the full path, you are using a relative path. Care should always be taken when using relative paths with commands. Look, for example, at the following code sample:

dir sub_dir

del *.*

In this example, a directory (dir) listing is taken of a subdirectory (sub_dir), and the following delete (del) command was working on the entire contents of the current directory, not the directory listing which was just retrieved. This is an easy mistake to make. When working with relative paths, double period (..) notation refers to a parent directory, and single period (.) notation refers to the current directory.

Most programs and commands can have their actions modified by providing options on the command line. These options are usually represented by one or more letters and are introduced to the command with either / or -. The - character is usually used with commands that come from (converted from) the Unix OS, but most MS-DOS programs have implemented /. These options are referred to as switches. dir /on /s is an example of the dir command using switches.

Table 5-2 summarizes some of the most important switches for the dir ­command.

Table 5-2 Switches for dir

Switch

Description

/ax

The /a switch is short for attributes. This switch provides a listing of files that have matching attributes. This switch must be used in conjunction with an additional letter to provide results. Five letters may be used: (d)irectory, (a)rchive, (h)idden, (s)ystem, and (r)ead-only. Use a minus sign with one of these five letters reverses the listing: For example, /a-d shows you things that are not directories.

/b

The /b command displays a bare listing. A bare listing does not include a separate section in the output that tells you the directory that you are working with, but rather displays a single-line listing, like this output from these example commands:

dir /b /s c:windows wunk*.*

c:windows wunk_16.exe

c:windows wunk_32.exe

dir /b c:windows wunk*.*

twunk_16.exe

twunk_32.exe

/ox

The /o switch is short for order by. This switch is similar to /a in that /o also requires an additional letter to tell it how to order or sort. The options available for sorting are (n)ame, (s)ize, (e)xtension, (a)ccessed date (earliest first), and (d)ate modified (earliest first). Using a minus sign (for example, /o-d) reverses the order. If you use the letter g after the o (for example, /ogd), directories will be grouped at the top of the list rather than mixed in.

/p

This switch pauses the screen after each full screen of text and waits for a key to be pressed. If you do not use this option, you can use the pipe-more command, which looks like this dir c:windows*.exe | more.

/s

This switch includes listings for each subdirectory under the directory listing.

/w

This switch displays text in a wide listing. It enables more text to be displayed onscreen by using multiple columns.

/x

This switch is used on Windows 2000 and Windows XP computers to display short and long filenames.

tip.eps In this chapter, you will see many switches for each of the command line tools, but these are not all of the possible switches. To see the complete list, type the command with a /? after it, like this:

dir /?

If you want to use the same set of switches each time you execute the dir command, use the dircmd environment variable. This variable can be set in the autoexec.bat file or at a command prompt, like this:

set dircmd=/on /w

Now, every time you use dir, you will get output that looks like this:

Volume in drive D is DRIVE_D

Volume Serial Number is FFFF-FFFF

Directory of D:DOS

[.]            [..]           CHOICE.COM     DELTREE.EXE    DOSHELP.HLP

DOSKEY.COM     EXPAND.EXE     FC.EXE         FDISK.EXE      HELP.COM

HELP.HLP       HIMEM.SYS      INTERLNK.EXE   INTERSVR.EXE   LOADFIX.COM

SMARTDRV.EXE   TREE.COM       

              15 File(s)        525,943 bytes

               2 Dir(s)     446,431,232 bytes free

tip.eps Note that the list is presented in wide format and sorted by name.

If you are using Windows and you want the setting of the dircmd variable to be saved, add the variable by using the Environment Variables settings in the System Control Panel, which you can get to by choosing Properties when you right-click My Computer (or Computer for Vista or newer users) to open the System Properties dialog box; then click the Advanced tab (or Advanced systems settings link for Vista or newer users) and the Environment Variables button.

mkdir

mkdir, or md, is used to create directories; there is no difference between the two commands other than their spelling.

The directory created will be in the current directory unless you provide an alternative path to the command, like this:

mkdir “c: empmy new directory”

chdir

chdir, or cd, is used to change the current directory for a drive to another directory. The drive need not be your current drive; this command can set a current directory on another drive. For example, if your current drive is C:, you could still use cd d:my_dir_on_d to change the current directory for the D: drive. You will not see a difference onscreen, but if you change to the D: drive by using d:, you will see that the current directory is set to d:my_dir_on_d. The current directory is important when you want to use other file operation commands, such as copy. If you only specify the drive that you want to work with, you will be working with the current directory on that drive. Take a look at this example:

D:somedirectory>c:

C:Documents and Settingsed>cd

C:>mkdir d:old_configs

C:>cd d:old_configs

C:>copy a*.bat d:

C:>copy c:c*.sys d:old_configs

The first line changes your current drive to C:. The second changes to the root directory of the current drive (c:). The third creates a new directory on the D: drive, and the fourth line sets old_configs as the current directory on the D: drive. You will see the copy command in the upcoming section “copy,” but the fifth line copies all files in the current directory that start with a and end with .bat to the current directory on the D: drive (currently old_configs). The last line copies all files from c: that start with c and end with .sys to d:old_configs. Lines 5 and 6 copy files from the same directory (c:); the relative path is used in line 5, and the absolute path is used in line 6. The destination directory in line 6 is also absolute, and the relative path or current directory is used in line 5. In both statements (lines 5 and 6), the same directories are used as the source and destination directories.

warning_bomb.eps Relative paths can save on typing, but they can also cause errors if you are not careful.

rmdir

rmdir, or rd, is used to remove or delete directories from your drive. Two rules are imposed on you: Before you delete a directory

diamonds.jpg The directory must be empty.

diamonds.jpg It cannot be the current directory.

You can empty a directory by using the del command to delete the files. To remove a directory, though, just specify its location after the rmdir command:

rmdir c: emove_me

If you are using Windows XP or a newer Windows OS, you can use an optional switch — /s — that will automatically delete subdirectories and files.

Copying and Moving Files

Doesn’t it seem like when you finally get things organized, it’s time to start all over again? When organizing and backing up files, you will often be required to copy or move files to new locations, either in another directory or on another disk. The following sections provide an overview of the commands that help you with these tasks.

fortheexam.eps All the command line tools in this section have not changed substantially since MS-DOS.

copy

The copy command expects you to give at least the name of the file you would like to copy. If you provide only one filename, the selected file is copied into the current directory. If you provide a source filename and a destination directory by using a command like

copy c:sourcemyfile.txt c:destination

the file will be copied into the destination directory. You can also rename files while you are copying them by using a command like this:

copy c:source*.bat c:destination*.old

The preceding command would copy all files with an extension of .bat from the source directory and rename them with an .old extension in the destination directory.

If you are about to overwrite an existing file, you will be prompted to confirm the operation. This can be suppressed if you use /Y at the end of your copy command. /Y answers “yes” to the copy command’s “confirm overwrite?” question. If you want to consistently overwrite destination files, you can set the copycmd environment variable to /Y in the same manner that you set the dircmd variable in the “dir” section, earlier in this chapter.

xcopy

Many times, you have to copy entire directory structures from one location to another. If you were to do this with the copy command, you would first have to create all the destination directories by using the md command. When using the xcopy command, though, you can perform this task in a minimal amount of time. To copy an existing directory named source to a new directory named destination, you would issue the following command:

xcopy c:source*.* c:destination*.*

To copy all the subdirectories as well, use

xcopy c:source*.* c:destination*.* /s

To also include empty directories, add the /e (empty) switch to the end of the command. To include just files with the archive attribute set, add the /a (archive) switch.

Like the copy command, adding /Y will overwrite files without asking for confirmation. The /Y tells the command to answer “yes” to all overwrite prompts.

robocopy.exe

The robocopy.exe command is a turbocharged version of the xcopy command used to copy files and directories between locations. As with xcopy, you need to specify at least a source directory and a destination directory. To copy an existing directory named source to a new directory named destination, you would issue the following command

robocopy.exe c:source c:destination

The robocopy.exe command supports a wide variety of options — and some of the most common are listed in Table 5-3 — but if you are interested in this useful command, explore all of the options using robocopy.exe /?.

Table 5-3 Switches for robocopy.exe

Switch

Description

/e

The /e switch will copy all source directories to the destination location, including empty directories.

/purge

The /purge option will delete destination directories that no longer exist in the source directory. This may be the case if you are running the robocopy.exe command a second time, after making changes to the source directory.

/z

The /z command copies the files in restartable mode, which is useful if copying large files over a slow network. If the file copy is interrupted, it can pick up in the middle of the file it was working on, rather than starting at the beginning of the file.

/b

This switch will copy the files in backup mode, which may be necessary if you have files that open by users, and robocopy.exe cannot get a lock on the file. Backup mode allows for files to copied without putting locks on the files.

/copyall

This switch will copy all file properties, including data, attributes, time stamps, NTFS permissions, owner information, and auditing information.

/mir

The /mir switch is the same as running robocopy.exe with both the /e and /purge switches.

/mot:m

This option will monitor the source directory, and will rerun the robocopy.exe command again if any changes are found within the number of minutes defined by the m.

/r:n

The option should be a mandatory option; it specifies how many times robocopy.exe should attempt to copy failed files. Specify the number of attempts with the n. The default is one million attempts.

/w:n

The /w switch works with /r, as it is the time in seconds (n) to wait between attempts to copy the failed files. The default is 30 seconds.

/v

To see a list of all of the files that are copied, use the /v switch.

/log: file

This switch will create a log file, listing all of the files that are copied, and save it in the file specification that follows the colon.

When robocopy.exe has completed its operation, it will display a summary. Here is an example of robocopy.exe copying a small temp directory with a subdirectory to a new location, temp2.

C:>robocopy.exe /mir /v c: emp c: emp2

-------------------------------------------------------------------------------

   ROBOCOPY     ::     Robust File Copy for Windows

-------------------------------------------------------------------------------

  Started : Fri Apr 06 20:57:25 2012

   Source : c: emp

     Dest : c: emp2

    Files : *.*

  Options : *.* /V /S /E /COPY:DAT /PURGE /MIR /R:1000000 /W:30

------------------------------------------------------------------------------

          New Dir          1    c: emp

100%        New File                  24        autoexec.old

          New Dir          1    c: empsub

100%        New File                  24        autoexec.bat

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras

    Dirs :         2         2         0         0         0         0

   Files :         2         2         0         0         0         0

   Bytes :        48        48         0         0         0         0

   Times :   0:00:00   0:00:00                       0:00:00   0:00:00

   Ended : Fri Apr 06 20:57:25 2012

From the output, you should see that two directories were created and two files were copied.

move

The move command moves files from one directory to another. It is also used to rename directories. To use the move command, you have to specify the name of the files you want to move and then specify the destination directory, like this:

move c:sourcesource_file.txt c:destination

This example moves the file source_file.txt into the directory c:­destination. If the destination directory does not exist, you will see an error message.

To rename the directory c:source, you need to use

move c:source destination

del

To delete or remove files or directories, you can use del or erase. Like earlier examples, these two commands are synonymous. If you want to delete multiple files, you have to use the * and ? wildcards. (Read about wildcards earlier in the chapter.) MS-DOS and Windows 9x allow you to delete only files with this command, but Windows 2000 and newer OSes also allow you to delete directories.

warning_bomb.eps It is very easy to unintentionally delete files (or delete the wrong files) when working with relative paths. When possible, use full pathnames to avoid ­mistakes.

ren

The ren command is used to rename files and directories. Similar to many of the commands that you have looked at, you specify the source name and a new name for the file or directory.

Making Comparisons

Of the many special function commands, this section looks at a few commands that can be used to compare files: diskcopy.com, diskcomp.com, and fc.exe.

fortheexam.eps All the command line tools in this section have not changed substantially since MS-DOS.

diskcopy.com and diskcomp.com

These two tools do not get very much use these days because they were designed to be used with floppy disks. Both commands take two parameters: the drive letter of the source disk, and the destination disk. Both parameters can be the same drive letter, such as diskcopy a: a:. The preceding command will copy the contents of drive a: to a temporary location and then ask for the target disk to be inserted in the a: drive. diskcopy.com will copy the contents of the disk to a new disk, and diskcomp.com will compare the contents of the two disks to ensure that there are no errors during or after the copy.

fc.exe

fc.exe — still a valid and useful tool — is used to compare the contents of two files and indicate the differences between the two files. This command is very useful when attempting to compare two very long configuration files for differences.

A variety of switches with this command allow you to modify how the output looks or how the comparisons are made. The basic format of the command requires that you specify the two files that you want to compare, using a format like this:

fc.exe c:oot.ini c:old-boot.ini

Listing 5-1 shows a sample of the fc.exe command in action.

Listing 5-1: fc.exe Command Example

C:>fc.exe boot.ini old-boot.ini

Comparing files boot.ini and OLD-BOOT.INI

***** boot.ini

[boot loader]

timeout=30

default=multi(0)disk(0)rdisk(0)partition(1)WINDOWS

***** OLD-BOOT.INI

[boot loader]

timeout=20

default=multi(0)disk(0)rdisk(0)partition(1)WINDOWS

*****

In this example, there is one difference between the two files, in the time out= line. By default, fc.exe shows the line before and after the difference in the files, and also shows you which lines came from which file.

Performing Diagnostics and Tuning Performance

At the command prompt, a few commands can be used to optimize and diagnose your computer. defrag.exe can be used to optimize your hard drive, and chkdsk.exe can be used to check your disk for errors.

The MS-DOS or command prompt versions of the defrag.exe and chkdsk.exe utilities have now been replaced by Windows versions.

defrag.exe

The purpose of the defrag.exe utility is to fix speed and performance problems with hard drives. As files are written to and then deleted from a disk, they leave holes or blank areas scattered around your drive. When you write files to a disk, they always write to the largest open spaces that are available to them. There will be times when the largest area is not large enough for the entire file, and the file will have to be split into pieces. These fragmented files are slower to access because the disk head has to keep moving to a new location on the drive. To defragment the files on your hard drive, use Computer Management in Windows, or defrag from the command line. To assist users with scripting solutions to use most tools, or to allow them to run the commands through command line only sessions on a server, Microsoft provides command line access to most Windows-based utilities.

In either case, you are using the defragmentation utility from Executive Software, and you have the option to analyze only or to force defragmentation when disk space is low.

tip.eps For more information about using Computer Management in Windows, see Book VI, Chapter 4.

fortheexam.eps defrag.exe does not exist for Windows 2000. It is available only on Windows XP and newer Windows operating systems.

chkdsk.exe

chkdsk.exe serves an important purpose within the Windows operating system. Its job is to check

diamonds.jpg The directory structure and directory entries for corruption

diamonds.jpg The disk for worn-out areas

Its purpose is to reduce the chance of data loss by catching corruption early and by fixing small problems before they become larger.

tip.eps For more information about chkdsk.exe, read Book VI, Chapter 4.

shutdown.exe

shutdown.exe is listed here as a diagnostic tool as it allows for the shutdown of the local computer or of a remote computer. This is useful when you want to perform a reboot at the end of a batch file or need to remotely reboot a computer which you have been performing maintenance or troubleshooting on. Table 5-4 summaries the main options for the shutdown.exe command.

Table 5-4 Switches for shutdown.exe

Switch

Description

/?

Displays help information for the command.

/i

This option displays the GUI window to let you execute the command with various options, but in a graphical manner.

/l

Do not shutdown the computer, log the current user off.

/s

Shutdown the computer.

/r

Shutdown and restart the computer.

/g

Shutdown and restart the computer, and then restart any registered applications.

/a

Abort a previously scheduled shutdown command.

/p

Immediately power off the computer rather than shutdown the computer.

/h

Hibernate the computer rather than shutdown the computer.

/e

Record the reason for the unexpected shutdown.

/m \computer name

Issue the command against a remote computer rather than the local computer. If you forget this option, you will be shutting down the local computer, which is an inconvenient and common mistake.

/t xxx

Time before the shutdown command is executed. The default is 30 seconds, but can be number of seconds up to 10 years in duration.

/c “Comment”

Comments on the reason for the shutdown. You are limited to 512 characters.

/f

Force running applications to be closed. Unsaved data in applications will be lost.

/d [p|u]xx:yy

This option provides the reason to shutdown tracker that runs on new versions of Windows (Windows 2003, Windows 2008, and Windows 7). The shutdown is either Planned or Unplanned. Refer to the output of the help command to determine appropriate values to use in the xx and yy positions.

A typical shutdown command to reboot a remote computer named testpc would look like:

shutdown.exe /t:60 /r /m \testpc

Working with Other Useful Commands

The rest of the utilities in this chapter defy easy classification. Although they serve a wide range of functions, they are all important in your computer’s usage.

attrib.exe

All files have five basic attributes:

diamonds.jpg a: Archive. Files that have been modified.

diamonds.jpg h: Hidden. Are not usually visible.

diamonds.jpg i: Not to be Indexed. Should not be included by the system indexing service. This attribute was added in Windows Vista.

diamonds.jpg r: Read-only. Cannot normally be deleted, nor can they be modified.

diamonds.jpg s: System. Have special file protection so that you may not delete or modify them.

tip.eps The archive attribute is used by some backup utilities to identify changed files for incremental backups.

The attrib command allows you to change these attributes. The attributes are added or removed from files by specifying the attribute with a + or - character in front of the filename, as in the following statement:

attrib -s -h +a +r c:*.sys

The preceding statement removes the system (s) and hidden (h) attributes while adding the archive (a) and read-only (r) attributes. Adding /s to the end of the line would apply the same attributes to all the files in the subdirectories as well.

diskpart.exe

To manage disk partitioning, if the need ever arises, Windows 2000 and newer Windows OSes use the Disk Management graphical disk partitioning tool. Windows XP and newer Windows OSes also use another command line tool: diskpart.exe. Although this tool is capable of all disk partitioning tasks, you need to use this tool only to perform rare disk partition changes that Disk Management cannot perform, such as expanding a partition on a basic disk. The need to use diskpart.exe has been reduced with the introduction of Windows 7, which incorporates the ability to expand those partitions into the Disk Management graphical tool.

The reason for not using diskpart.exe is that its user interface is awkward. To illustrate the interface, Listing 5-2 holds the steps required to create a partition on a disk and format the drive (extra blank lines have been removed):

Listing 5-2: Creating a Partition on a Disk and Formatting the Drive

C:>diskpart.exe

DISKPART>list disk

  Disk ###  Status      Size     Free     Dyn  Gpt

  --------  ----------  -------  -------  ---  ---

  Disk 0    Online      6142 MB      0 B

  Disk 1    Online       510 MB      0 B

  Disk 2    Online      6142 MB  6142 MB

DISKPART> select disk 2

Disk 2 is now the selected disk.

DISKPART> create partition primary size=1000

DiskPart succeeded in creating the specified partition.

DISKPART> list partition

  Partition ###  Type              Size     Offset

  -------------  ----------------  -------  -------

  Partition 1    Primary           1004 MB    32 KB

DISKPART> select partition 1

Partition 1 is now the selected partition.

DISKPART> assign letter=f

DiskPart successfully assigned the drive letter or mount point.

DISKPART> exit

Leaving DiskPart...

C:>format f: /fs:ntfs

The type of the file system is RAW.

The new file system is NTFS.

WARNING, ALL DATA ON NON-REMOVABLE DISK

DRIVE F: WILL BE LOST!

Proceed with Format (Y/N)? y

Verifying 1004M

Volume label (ENTER for none)? More Data

Creating file system structures.

Format complete.

   1028128 KB total disk space.

   1020600 KB are available.

This process could have been completed through a single wizard in Disk Management, with less effort.

format.com

Using the format.com command prepares a disk to be used by your computer. The purposes of this command are to

diamonds.jpg Check whether all clusters on the partition are in working order.

diamonds.jpg Create the directory table.

On FAT partitions, the directory table is referred to as the File Allocation Table. The directory table maintains a list of where each file starts on the disk.

The format command requires a drive letter and supports additional switches. The proper syntax to format your A: drive is

format a:

You could modify the command by adding /q to the end of the line to perform a quick format of the drive.

tip.eps The quick format doesn’t check the integrity of the sectors on the drive but only deletes and re-creates the directory table.

If you are using Windows 2000 or newer Windows OS, you can use /FS:filesystem to specify the format of the partition as either FAT, FAT32, or NTFS.

ver

The ver command indicates what version of the command prompt you are running. This varies between copies of Windows, as shown in Table 5-5. For example, using ver with Windows 9x OSes lets you see that they are all sub-versions of Windows 4.0, and all copies of newer versions of Windows and (Windows XP/Vista/7) are sub-versions of Windows NT 5.0 or Windows NT 6.0. Major and minor version numbers from software manufacturers let you know how much they think the software has changed, so architecturally, each of these OSes has not changed significantly since their initial releases.

Table 5-5 Windows ver Output

Version

Output of ver Command

Windows 95 Retail

Windows 95 [Version 4.00.0095]

Windows 95 OSR2

Windows 95 [Version 4.00.1111]

Windows 98

Windows 98 [Version 4.10.1998]

Windows 98 SE

Windows 98 [Version 4.10.2154]

Windows 2000 Professional

Microsoft Windows 2000 [Version 5.00.2195]

Windows XP Professional

Microsoft Windows XP [Version 5.1.2600]

Windows Server 2003

Microsoft Windows [Version 5.2.3790]

Windows Vista

Microsoft Windows [Version 6.0.6001]

Windows Server 2008

Microsoft Windows [Version 6.0.6001]

Windows 7

Microsoft Windows [Version 6.1.7600]

Windows Server 2008 R2

Microsoft Windows [Version 6.1.7600]

help

If you need to know how to do something with the command line, you have two main options. All commands support /? as a switch to get additional information on how to use the command. Additionally, Windows XP and newer versions of Windows also have a help command.

Use help followed by the command that you would like to get help on: for example

help help

If you use help by itself, you get a list of commands that you can request help for.

Getting an A+

The most important things to remember from this chapter are what the different commands are used for and the major differences between similar commands. Here is a quick review:

diamonds.jpg attrib changes file attributes, such as read-only, hidden, system, and archive.

diamonds.jpg copy copies one or multiple files from one directory to another.

diamonds.jpg defrag defragments your hard drive to increase performance.

diamonds.jpg dir displays a list of files in a directory or directories.

diamonds.jpg format prepares a disk for accepting data or to erase a disk.

diamonds.jpg chkdsk checks a disk for errors that could cause data loss.

diamonds.jpg ver displays the version of Windows that is in use.

diamonds.jpg xcopy is like copy but can be used to copy entire directory structures.

Prep Test

1 You are working on the help desk, and you receive a call from Mary. She is looking for a file that is saved on her hard drive. She has forgotten the name she gave it, but she knows that the title contains the word “budget” and that it is a Microsoft Excel spreadsheet. What command will best help her locate her document?

A checkbox.jpg dir *budget.xls

B checkbox.jpg dir *budget*.xls /b

C checkbox.jpg dir *.budget*.xls /s

D checkbox.jpg dir *budget*.xls /b /s

2 You need to regularly back up files in a directory, but you want to back up only files that have changed. What commands can you use to accomplish this in the easiest way possible?

A checkbox.jpg fc and xcopy

B checkbox.jpg attrib and copy

C checkbox.jpg fc, changes, and xcopy

D checkbox.jpg xcopy and attrib

3 You want to copy a directory structure (complete with subdirectories), so you use copy c:dir1*.* c: ewdir /s /e. What will you find in the newdir directory?

A checkbox.jpg All files that were in dir1

B checkbox.jpg All files and subdirectories that were in dir1

C checkbox.jpg Nothing — the command is improperly constructed and will generate an error

D checkbox.jpg None of the above

4 You receive a call from a user on your network complaining that his computer is slow. You ask a few more questions and find out that he feels that the speed of his hard drive is much slower than when he got his computer. What command would you suggest running?

A checkbox.jpg diskfix

B checkbox.jpg quikdisk

C checkbox.jpg scanfix

D checkbox.jpg defrag

Answers

1 D. Although C looks like a good choice as well, using the subdirectory switch, it has an additional period in the search string, so will not return as many files and will work only if Mary’s document has a period in front of the word budget. See “dir.”

2 D. The attrib.exe command can be used to remove the archive attribute from all files in a directory structure. Then, as files are modified, you can use xcopy *.* c:ackuplocation /s /a to copy all the files to a new location. If you want your next copy to copy the files that were modified since the last copy, you have to use the attrib command to remove the archive attribute again. Check out “xcopy.”

3 C. The suggested command will cause a syntax error, and nothing will be copied. The copy command does not support either /s or /e; to use these options, you have to use the xcopy.exe command. Peruse “xcopy.”

4 D. defrag is used to reorganize files, which speeds up access to the disk. Check out “defrag.exe.”

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset