Command Line Utilities

Attrib

Displays, sets, or removes the read-only, archive, system, and hidden attributes assigned to files or directories. Used without parameters, attrib displays attributes of all files in the current directory.

Syntax

attrib [{+r | -r}] [{+a | -a}] [{+s | -s}] [{+h | -h}] [[Drive:][Path] FileName] [/s[/d]]

Parameters

+r

Sets the read-only file attribute.

-r

Clears the read-only file attribute.

+a

Sets the archive file attribute.

-a

Clears the archive file attribute.

+s

Sets the system file attribute.

-s

Clears the system file attribute.

+h

Sets the hidden file attribute.

-h

Clears the hidden file attribute.

[Drive:][Path] FileName

Specifies the location and name of the directory, file, or set of files for which you want to display or change attributes. You can use wildcard characters (that is, ? and *) in the FileName parameter to display or change the attributes for a group of files.

/s

Applies attrib and any command-line options to matching files in the current directory and all of its subdirectories.

/d

Applies attrib and any command-line options to directories.

/?

Displays help at the command prompt.

Cmd

Starts a new instance of the command interpreter, Cmd.exe. Used without parameters, cmd displays the version and copyright information of the operating system.

Syntax

cmd [{/c | /k}] [/s] [/q] [/d] [{/a | /u}] [/t:FG] [/e:{on | off}] [/f:{on | off}] [/v:{on | off}] [String]

Parameters

/c

Carries out the command specified by String and then stops.

/k

Carries out the command specified by String and continues.

/s

Modifies the treatment of String after /c or /k.

/q

Turns the echo off.

/d

Disables execution of AutoRun commands.

/a

Formats internal command output to a pipe or a file as American National Standards Institute (ANSI).

/u

Formats internal command output to a pipe or a file as Unicode.

/t:FG

Sets the foreground F and background G colors. The following tables lists valid hexadecimal digits that you can use as the values for F and G.

Value Color
0 Black
1 Blue
2 Green
3 Aqua
4 Red
5 Purple
6 Yellow
7 White
8 Gray
9 Light blue
A Light green
B Light aqua
C Light red
D Light purple
E Light yellow
F Bright white

/e:on

Enables command extensions.

/e:off

Disables commands extensions.

/f:on

Enables file and directory name completion.

/f:off

Disables file and directory name completion.

/v:on

Enables delayed environment variable expansion.

/v:off

Disables delayed environment variable expansion.

String

Specifies the command you want to carry out.

/?

Displays help at the command prompt.

Copy

Copies one or more files from one location to another.

Syntax

copy [/d] [/v] [/n] [{/y | /-y}] [/z] [{/a | /b}] Source [{/a | /b}] [+ Source [{/a | /b}] [+ …]] [Destination [{/a | /b}]]

Parameters

/d

Allows the encrypted files being copied to be saved as decrypted files at the destination.

/v

Verifies that new files are written correctly.

/n

Uses a short file name, if available, when copying a file with a name longer than eight characters, or with a file extension longer than three characters.

/y

Suppresses prompting to confirm that you want to overwrite an existing destination file.

/-y

Prompts you to confirm that you want to overwrite an existing destination file.

/z

Copies networked files in restartable mode.

/a

Indicates an ASCII text file.

/b

Indicates a binary file.

Source

Required. Specifies the location from which you want to copy a file or set of files. Source can consist of a drive letter and colon, a folder name, a file name, or a combination of these.

Destination

Required. Specifies the location to which you want to copy a file or set of files. Destination can consist of a drive letter and colon, a folder name, a file name, or a combination of these.

/?

Displays help at the command prompt.

Defrag

Locates and consolidates fragmented boot files, data files, and folders on local volumes.

Syntax

defrag Volume

defrag Volume [/a]

defrag Volume [/a] [/v]

defrag Volume [/v]

defrag Volume [/f]

Parameters

Volume

The drive letter or a mount point of the volume to be defragmented.

/a

Analyzes the volume, displays a summary of the analysis report, and indicates whether you should defragment the volume.

/v

Displays the complete analysis and defragmentation reports. When used in combination with /a, displays only the analysis report. When used alone, displays both the analysis and defragmentation reports.

/f

Forces defragmentation of the volume when free space is low.

/?

Displays help at the command prompt.

Del (erase)

Deletes specified files.

Syntax

del [Drive:][Path] FileName [ …] [/p] [/f] [/s] [/q] [/a[:Attributes]]

erase [Drive:][Path] FileName [ …] [/p] [/f] [/s] [/q] [/a[:Attributes]]

Parameters

[Drive:][Path] FileName

Specifies the location and name of the file or set of files you want to delete. FileName is required. You can use multiple file names. Separate file names with spaces, commas, or semicolons.

/p

Prompts you for confirmation before deleting the specified file.

/f

Forces deletion of read-only files.

/s

Deletes specified files from the current directory and all subdirectories. Displays the names of the files as they are being deleted.

/q

Specifies quiet mode. You are not prompted for delete confirmation.

/a

Deletes files based on specified attributes.

Attributes

Specifies any of the file attributes listed in the following table.

Attribute Description
r Read-only
a Archive
s System
h Hidden
Prefix that means NOT

/?

Displays help at the command prompt.

Rename (ren)

Changes the name of a file or a set of files.

Syntax

rename [Drive:][Path] FileName1 FileName2

ren [Drive:][Path] FileName1 FileName2

Parameters

[Drive:][Path] FileName1

Specifies the location and name of the file or set of files you want to rename.

FileName2

Specifies the new name for the file. If you use wildcards (* and ?), FileName2 specifies the new names for the files. You cannot specify a new drive or path when renaming files.

/?

Displays help at the command prompt.

Deltree

Deletes a directory and all the subdirectories and files in it.

To delete one or more files and directories:

DELTREE [/Y] [drive:]path [[drive:]path[…]]

/Y              Suppresses prompting to confirm you want to delete

the subdirectory.

[drive:]path    Specifies the name of the directory you want to delete.

Note: Use DELTREE cautiously. Every file and subdirectory within the

specified directory will be deleted.

Dir

Displays a list of a directory’s files and subdirectories. Used without parameters, dir displays the disk’s volume label and serial number, followed by a list of directories and files on the disk, including their names and the date and time each was last modified. For files, dir displays the name extension and the size in bytes. Dir also displays the total number of files and directories listed, their cumulative size, and the free space (in bytes) remaining on the disk.

Syntax

dir [Drive:][Path][FileName] […] [/p] [/q] [/w] [/d] [/a[[:]Attributes]][/o[[:]SortOrder]] [/t[[:]TimeField]] [/s] [/b] [/l] [/n] [/x] [/c] [/4]

Parameters

[Drive:][Path]

Specifies the drive and directory for which you want to see a listing.

[FileName]

Specifies a particular file or group of files for which you want to see a listing.

/p

Displays one screen of the listing at a time. To see the next screen, press any key on the keyboard.

/q

Displays file ownership information.

/w

Displays the listing in wide format, with as many as five file names or directory names on each line.

/d

Same as /w but files are sorted by column.

/a [[:] Attributes]

Displays only the names of those directories and files with the attributes you specify. If you omit /a, dir displays the names of all files except hidden and system files. If you use /a without specifying Attributes, dir displays the names of all files, including hidden and system files. The following list describes each of the values you can use for Attributes. The colon (:) is optional. Use any combination of these values, and do not separate the values with spaces.

Value Description
h Hidden files
s System files
d Directories
a Files ready for archiving
r Read-only files
-h Files that are not hidden
-s Files other than system files
-d Files only (not directories)
-a Files that have not changed since the last backup
-r Files that are not read-only

/o [[:]SortOrder]

Controls the order in which dir sorts and displays directory names and file names. If you omit /o, dir displays the names in the order in which they occur in the directory. If you use /o without specifying SortOrder, dir displays the names of the directories, sorted in alphabetic order, and then displays the names of files, sorted in alphabetic order. The colon (:) is optional. The following list describes each of the values you can use for SortOrder. Use any combination of the values, and do not separate these values with white spaces.

Value Description
n In alphabetic order by name
e In alphabetic order by extension
d By date and time, earliest first
s By size, smallest first
g With directories grouped before files
-n In reverse alphabetic order by name (Z through A)
-e In reverse alphabetic order by extension (.ZZZ through .AAA)
-d By date and time, latest first
-s By size, largest first
-g With directories grouped after files

/t [[:]TimeField]

Specifies which time field to display or use for sorting. The following list describes each of the values you can use for TimeField.

Value Description
c Creation
a Last access
w Last written

/s

Lists every occurrence, in the specified directory and all subdirectories, of the specified file name.

/b

Lists each directory name or file name, one per line, including the file name extension. /b does not display heading information or a summary. /b overrides /w.

/l

Displays unsorted directory names and file names in lowercase. /l does not convert extended characters to lowercase.

/n

Displays a long list format with file names on the far right of the screen.

/x

Displays the short names generated for files on NTFS and FAT volumes. The display is the same as the display for /n, but short names are displayed after the long name.

/c

Displays the thousand separator in file sizes.

/4

Displays four-digit year format.

/?

Displays help at the command prompt.

Echo

Turns the command echoing feature on or off, or displays a message. Used without parameters, echo displays the current echo setting.

Syntax

echo [{on | off}] [Message]

Parameters

{on | off}

Specifies whether to turn the command echoing feature on or off.

Message

Specifies the text that you want to display on the screen.

/?

Displays help at the command prompt.

Edit

EDIT [/B] [/H] [/R] [/S] [/<nnn>] [/?] [file(s)]

/B       – Forces monochrome mode.

/H       – Displays the maximum number of lines possible for your hardware.

/R       – Load file(s) in read-only mode.

/S       – Forces the use of short filenames.

/<nnn>   – Load binary file(s), wrapping lines to <nnn> characters wide.

/?       – Displays this help screen.

[file]   – Specifies initial files(s) to load.  Wildcards and multiple

filespecs can be given.

Fdisk

Configures a hard disk for use with MS-DOS. (Not available for Windows 2000/XP/2003)

FDISK [/STATUS] /X

/STATUS   Displays partition information.

/X        Ignores extended disk-access support. Use this switch if you

receive disk access or stack overflow messages.

Format

Formats the disk in the specified volume to accept Windows files.

Syntax

format Volume [/fs:FileSystem] [/v:Label] [/q] [/a:UnitSize] [/c] [/x]

format Volume [/v:Label] [/q] [/f:Size]

format Volume [/v:Label] [/q] [/t:Tracks /n:Sectors]

format Volume [/v:Label] [/q]

format Volume [/q]

format Volume [/s]

Parameters

Volume

Specifies the mount point, volume name, or drive letter (followed by a colon), of the drive you want to format. If you do not specify any of the following command-line options, format uses the volume type to determine the default format for the disk.

/fs:FileSystem

Specifies the file system to use file allocation table (FAT), FAT32, or NTFS. Floppy disks can use only the FAT file system.

/v:Label

Specifies the volume label. If you omit the /v command-line option or use it without specifying a volume label, format prompts you for the volume label after the formatting is completed. Use the syntax /v: to prevent the prompt for a volume label. If you format more than one disk by using one format command, all of the disks will be given the same volume label. For more information about disk volume labels, see Related Topics.

/a:UnitSize

Specifies the allocation unit size to use on FAT, FAT32, or NTFS volumes. If you do not specify UnitSize, it is chosen based on volume size. The following table lists valid values for UnitSize.

Value Description
512 Creates 512 bytes per cluster.
1024 Creates 1024 bytes per cluster.
2048 Creates 2048 bytes per cluster.
4096 Creates 4096 bytes per cluster.
8192 Creates 8192 bytes per cluster.
16K Creates 16 kilobytes per cluster.
32K Creates 32 kilobytes per cluster.
64K Creates 64 kilobytes per cluster.

/q

Performs a quick format. Deletes the file table and the root directory of a previously formatted volume but does not perform a sector by sector scan for bad areas. You should use the /q command-line option to format only previously formatted volumes that you know are in good condition.

/f:Size

Specifies the size of the floppy disk to format. When possible, use this command-line option instead of the /t and /n command-line options. Windows accepts the following value for size:

1440 or 1440k or 1440kb or 1.44 or 1.44m or 1.44mb
1.44-MB, double-sided, quadruple-density, 3.5-inch disk

/t:Tracks

Specifies the number of tracks on the disk. When possible, use the /f command-line option instead of this command-line option. If you use the /t command-line option, you must also use the /n command-line option. These two command-line options provide an alternative method of specifying the size of the disk being formatted. You cannot use the /f command-line option with the /t command-line option.

/n:Sectors

Specifies the number of sectors per track. When possible, use the /f command-line option instead of this command-line option. If you use the /n command-line option, you must also use the /t command-line option. These two command-line options provide an alternative method of specifying the size of the disk being formatted. You cannot use the /f command-line option with the /n command-line option.

/c

NTFS only. Files created on the new volume will be compressed by default.

/x

Causes the volume to dismount, if necessary, before it is formatted. Any open handles to the volume will no longer be valid.

/s

Copies system files to the formatted disk. (Windows 9x only)

MD/CD/RD

Mkdir (MD)

Creates a directory or subdirectory.

Syntax

mkdir [Drive:]Path

md [Drive:]Path

Parameters

Drive:

Specifies the drive on which you want to create the new directory.

Path

Required. Specifies the name and location of the new directory. The maximum length of any single path is determined by the file system.

/?

Displays help at the command prompt.

Displays the name of or changes the current directory.

CHDIR (CD)

CHDIR [/D] [drive:][path]

CHDIR [..]

CD [/D] [drive:][path]

CD [..]

..   Specifies that you want to change to the parent directory.

Type CD drive: to display the current directory in the specified drive.

Type CD without parameters to display the current drive and directory.

Use the /D switch to change current drive in addition to changing current

directory for a drive.

If Command Extensions are enabled CHDIR changes as follows:

The current directory string is converted to use the same case as

the on disk names.  So CD C:\TEMP would actually set the current

directory to C:\Temp if that is the case on disk.

CHDIR command does not treat spaces as delimiters, so it is possible to

CD into a subdirectory name that contains a space without surrounding

the name with quotes.  For example:

cd \winnt\profiles\username\programs\start menu

is the same as:

cd “\winnt\profiles\username\programs\start menu”

which is what you would have to type if extensions were disabled.

Rmdir (rd)

Removes (that is, deletes) a directory.

Syntax

rmdir [Drive:]Path [/s] [/q]

rd [Drive:]Path [/s] [/q]

Parameters

[Drive:]Path

Specifies the location and name of the directory that you want to delete.

/s

Removes the specified directory and all subdirectories including any files. Use /s to remove a tree.

/q

Runs rmdir in quiet mode. Deletes directories without confirmation.

/?

Displays help at the command prompt.

MEM

Displays the amount of used and free memory in your system.

MEM [/PROGRAM | /DEBUG | /CLASSIFY]

/PROGRAM or /P   Displays status of programs currently loaded in memory.

/DEBUG or /D     Displays status of programs, internal drivers, and other

information.

/CLASSIFY or /C  Classifies programs by memory usage. Lists the size of

programs, provides a summary of memory in use, and lists

largest memory block available.

Ping

Verifies IP-level connectivity to another TCP/IP computer by sending Internet Control Message Protocol (ICMP) Echo Request messages. The receipt of corresponding Echo Reply messages are displayed, along with round-trip times. Ping is the primary TCP/IP command used to troubleshoot connectivity, reachability, and name resolution. Used without parameters, ping displays help.

Syntax

ping [-t] [-a] [-n Count] [-l Size] [-f] [-i TTL] [-v TOS] [-r Count] [-s Count] [{-j HostList | -k HostList}] [-w Timeout] [-R] [-S SrcAddr] [-4] [-6] TargetName

Parameters

-t

Specifies that ping continue sending Echo Request messages to the destination until interrupted. To interrupt and display statistics, press CTRL+BREAK. To interrupt and quit ping, press CTRL+C.

-a

Specifies that reverse name resolution is performed on the destination IP address. If this is successful, ping displays the corresponding host name.

-n Count

Specifies the number of Echo Request messages sent. The default is 4.

-l Size

Specifies the length, in bytes, of the Data field in the Echo Request messages sent. The default is 32. The maximum Size is 65,527.

-f

Specifies that Echo Request messages are sent with the Don’t Fragment flag in the IP header set to 1 (available on IPv4 only). The Echo Request message cannot be fragmented by routers in the path to the destination. This parameter is useful for troubleshooting path Maximum Transmission Unit (PMTU) problems.

-i TTL

Specifies the value of the TTL field in the IP header for Echo Request messages sent. The default is the default TTL value for the host. The maximum TTL is 255.

-v TOS

Specifies the value of the Type of Service (TOS) field in the IP header for Echo Request messages sent (available on IPv4 only). The default is 0. TOS is specified as a decimal value from 0 through 255.

-r Count

Specifies that the Record Route option in the IP header is used to record the path taken by the Echo Request message and corresponding Echo Reply message (available on IPv4 only). Each hop in the path uses an entry in the Record Route option. If possible, specify a Count that is equal to or greater than the number of hops between the source and destination. The Count must be a minimum of 1 and a maximum of 9.

-s Count

Specifies that the Internet Timestamp option in the IP header is used to record the time of arrival for the Echo Request message and corresponding Echo Reply message for each hop. The Count must be a minimum of 1 and a maximum of 4. This is required for link-local destination addresses.

-j HostList

Specifies that the Echo Request messages use the Loose Source Route option in the IP header with the set of intermediate destinations specified in HostList (available on IPv4 only). With loose source routing, successive intermediate destinations can be separated by one or multiple routers. The maximum number of addresses or names in the host list is 9. The host list is a series of IP addresses (in dotted decimal notation) separated by spaces.

-k HostList

Specifies that the Echo Request messages use the Strict Source Route option in the IP header with the set of intermediate destinations specified in HostList (available on IPv4 only). With strict source routing, the next intermediate destination must be directly reachable (it must be a neighbor on an interface of the router). The maximum number of addresses or names in the host list is 9. The host list is a series of IP addresses (in dotted decimal notation) separated by spaces.

-w Timeout

Specifies the amount of time, in milliseconds, to wait for the Echo Reply message that corresponds to a given Echo Request message to be received. If the Echo Reply message is not received within the time-out, the “Request timed out” error message is displayed. The default time-out is 4000 (4 seconds).

-R

Specifies that the round-trip path is traced (available on IPv6 only).

-S SrcAddr

Specifies the source address to use (available on IPv6 only).

-4

Specifies that IPv4 is used to ping. This parameter is not required to identify the target host with an IPv4 address. It is only required to identify the target host by name.

-6

Specifies that IPv6 is used to ping. This parameter is not required to identify the target host with an IPv6 address. It is only required to identify the target host by name.

TargetName

Specifies the host name or IP address of the destination.

/?

Displays help at the command prompt.

SCANDISK

Windows 9x utility to scan for file, folder, and physical disk errors. For Windows NT/2000/XP/2003 use CHKDSK.

SCANREG

Scans and backs up Registry for Windows 98/ME

Usage: SCANREG [/<option>]

<option>

?          : Displays usage.

BACKUP     : Backup the registry and related system configuration files.

RESTORE    : Choose a backup to restore.

FIX        : Repair the registry.

COMMENT=”<comment>”

: Adds the specified comment to the CAB file while backing up.

Set

Displays, sets, or removes environment variables. Used without parameters, set displays the current environment settings.

Syntax

set [[/a [Expression]] [/p [Variable=]] String]

Parameters

/a

Sets String to a numerical expression that is evaluated.

/p

Sets the value of Variable to a line of input.

Variable

Specifies the variable you want to set or modify.

String

Specifies the string you want to associate with the specified variable.

/?

Displays help at the command prompt.

Setver

Sets the MS-DOS version number that Windows reports to a program.

Display current version table:  SETVER [drive:path]

Add entry:                      SETVER [drive:path] filename n.nn

Delete entry:                   SETVER [drive:path] filename /DELETE [/QUIET]

[drive:path]    Specifies location of the SETVER.EXE file.

filename        Specifies the filename of the program.

n.nn            Specifies the MS-DOS version to be reported to the program.

/DELETE or /D   Deletes the version-table entry for the specified program.

/QUIET or /Q    Hides the message typically displayed during deletion of

version-table entry.

Type

Displays the contents of a text file. Use the type command to view a text file without modifying it.

Syntax

type [Drive:][Path] FileName

Parameters

[Drive:][Path] FileName

Specifies the location and name of the file or files that you want to view. Separate multiple file names with spaces.

/?

Displays help at the command prompt.

Ver

Displays the operating system version number.

Xcopy

Copies files and directories, including subdirectories.

Syntax

xcopy Source [Destination] [/w] [/p] [/c] [/v] [/q] [/f] [/l] [/g] [/d[:MM-DD-YYYY]] [/u] [/i] [/s [/e]] [/t] [/k] [/r] [/h] [{/a | /m}] [/n] [/o] [/x] [/exclude:FileName1[+[FileName2]][+[FileName3]] [{/y | /-y}] [/z]

Parameters

Source

Required. Specifies the location and names of the files you want to copy. This parameter must include either a drive or a path.

Destination

Specifies the destination of the files you want to copy. This parameter can include a drive letter and colon, a directory name, a file name, or a combination of these.

/w

Displays the following message and waits for your response before starting to copy files:

Press any key to begin copying file(s)

/p

Prompts you to confirm whether you want to create each destination file.

/c

Ignores errors.

/v

Verifies each file as it is written to the destination file to make sure that the destination files are identical to the source files.

/q

Suppresses the display of xcopy messages.

/f

Displays source and destination file names while copying.

/l

Displays a list of files that are to be copied.

/g

Creates decrypted destination files.

/d[:MM-DD-YYYY]

Copies source files changed on or after the specified date only. If you do not include a MM-DD-YYYY value, xcopy copies all Source files that are newer than existing Destination files. This command-line option allows you to update files that have changed.

/u

Copies files from Source that exist on Destination only.

/i

If Source is a directory or contains wildcards and Destination does not exist, xcopy assumes destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts you to specify whether Destination is a file or a directory.

/s

Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory.

/e

Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options.

/t

Copies the subdirectory structure (that is, the tree) only, not files. To copy empty directories, you must include the /e command-line option.

/k

Copies files and retains the read-only attribute on destination files if present on the source files. By default, xcopy removes the read-only attribute.

/r

Copies read-only files.

/h

Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files.

/a

Copies only source files that have their archive file attributes set. /a does not modify the archive file attribute of the source file. For information about how to set the archive file attribute by using attrib, see Related Topics.

/m

Copies source files that have their archive file attributes set. Unlike /a, /m turns off archive file attributes in the files that are specified in the source. For information about how to set the archive file attribute by using attrib, see Related Topics.

/n

Creates copies by using the NTFS short file or directory names. /n is required when you copy files or directories from an NTFS volume to a FAT volume or when the FAT file system naming convention (that is, 8.3 characters) is required on the destination file system. The destination file system can be FAT or NTFS.

/o

Copies file ownership and discretionary access control list (DACL) information.

/x

Copies file audit settings and system access control list (SACL) information (implies /o).

/exclude:FileName1[+[FileName2]][+[FileName3]]

Specifies a list of files containing strings.

/y

Suppresses prompting to confirm that you want to overwrite an existing destination file.

/-y

Prompts to confirm that you want to overwrite an existing destination file.

/z

Copies over a network in restartable mode.

/?

Displays help at the command prompt.