Вы находитесь на странице: 1из 30

Guide to Windows Commands

Guide to Windows Commands


This book aims to introduce users of Microsoft Windows to command interpreters on that operating system and to the wide range of command-line tools that are available, which may come as a surprise to those who think of it as purely a graphical user interface operating system. The Microsoft-supplied command interpreter on Windows NT is cmd.exe. You can find out which version of cmd.exe you are running using the VER command. C:\>VER Microsoft Windows XP [Version 5.1.2600] C:\> There are other command interpreters available, such as 4NT from JP Software and CMD from the ReactOS project. This book will cover them all. It starts by considering cmd.exe and then looks at differences in the other command interpreters. This book first describes using command interpreters how they receive, parse, and process commands from users. Then it describes the various commands available.

The Windows Command Line


MS-DOS was a big leap forwards in the home user PC market in the 80s. It allowed novice computer users to control their computers without having to learn languages like BASIC. DOS exposed the computers underlying hardware in a safe and usable way in the form of commands. For example, at the nostalgic dos prompt: A:/>_ , it was this prompt that spawned the ever increasing use of Microsoft DOS on personal computers. Today the prompt or CLI (Command Line Interface) has been replaced with the more interactive GUI (Graphical User Interface), though interestingly enough 'power users' still prefer the use of the CLI, or the 'DOS BOX' where repetitive or complicated tasks can be performed with a higher degree of control or use-ability. In cases where GUI software hasn't been developed to complete a specific task, commands can be strung together to accomplish a given task through a CLI. It can be started by finding it in the All Programs menu or by typing cmd in a run dialog box or the search box of the Start menu.

Guides to DOS commands


This book addresses 32-bit Windows commands applicable to modern versions of Windows based on the Windows NT environment. It does not address commands that are specific to DOS environments and to DOS-based operating systems, such as Windows 95, Windows 98, and Windows Me (whose Microsoft-supplied command interpreters are in fact DOS programs, not Win32 programs). There are several guides to DOS commands available that are licensed under the GNU Free Documentation License: The FreeDOS HTML Help [1] at fdos.org [2] is a fully hypertext help system for FreeDOS commands, written in 2003/2004 The FreeDOS Spec [3] at SourceForge is a plaintext specification, written in 1999, for how DOS commands should work in FreeDOS To find a list of all MS-DOS commands and a definition for all of them, open the command prompt on all Microsoft/Windows computers, and type help

Guide to Windows Commands

Using command interpreters


How a command line is interpreted
The parsing of a command line into a sequence of commands is complex, and varies subtly from command interpreter to command interpreter. There are, however, four main components: Variable substitution A command line is scanned for variable specifications, and any found are replaced with the contents of those variables. Quoting Special characters can be quoted, to remove their special meanings. Syntax Command lines are devolved into a sequence of commands according to a syntax. Redirection Redirection specifications are applied, and removed from the command line, before an individual command in a sequence is executed. Variable substitution Command lines can contain variable specifications. These comprise a % character followed by a name. In Microsoft's CMD, the name is ended by a second % character, except in special cases such as the batch file parameters %1, %2, and so forth. In 4NT, the name is ended either by a second % character or a "pseudo-whitespace" character (i.e. any character that the old COMMAND interpreter for MS-DOS version 2 considered to be "whitespace" for the purposes of parsing), with special cases for batch file parameters and for platform-neutral metacharacters. Variable specifications are replaced with values. The value used to replace a variable specification is as follows: (4NT only) For the variable specifications %+ and %=, the expansion is the current value of a particular metacharacter, for %+ being the metacharacter for command separator and for %= being the metacharacter for quoting. The reason for this is that 4NT allows the metacharacters to be changed with the SETDOS and OPTION commands. The special %+ and %= specifications allow batch file writers to write batch files that will work irrespective of what the current metacharacters may actually have been set to by the user; whereas a batch file written assuming that & is the command separator metacharacter will not work correctly if the command separator metacharacter is changed. For variable specification names that match the names of environment variables, the replacement is the value of the named environment variable. For example: %PATH% is replaced by the value of the PATH environment variable. For variable specifications that name batch file parameters (i.e. that are non-negative decimal numbers), the replacement is the value of the parameter taken from the arguments with which the batch file was invoked (subject to any subsequent modifications by the SHIFT command). For example: %2 is replaced by the value of the second batch file parameter. (4NT only) For variable specification names that do not match the names of environment variables, but that do match various "special" names, the replacement is a special value (usually constructed on the fly) that the name represents.

Guide to Windows Commands Special names This is a list of the special names and what they expand to:
Name _CWD _CWDS %CD% Replacement Value Used (4NT only)The current working directory, not ending in a slash character if it is not the root directory of the current drive (4NT only)The current working directory, guaranteed to end in a slash character The current directory, not ending in a slash character if it is not in the root directory of the current drive

%TIME% The system time in HH:MM:SS.mm format. %DATE% The system date in YYYY-MM-DD format

This table is incomplete. You can help Wikibooks by expanding it. Quoting To prevent the metacharacters that control command syntax and redirection from having their special meanings, quoting is used. This takes two forms: Although they don't process quotation marks, in command arguments, specially themselves, but simply pass them along as-is to the commands executed, command interpreters do recognise when quotation marks (") surround metacharacters. The & metacharacter does not have its usual effect on command syntax if it is within a pair of quotation marks. e.g. The command line echo "&" will invoke the ECHO command passing it the three characters "&" as its command tail, rather than split the command line in twain at the & character as would occur if the character were not within quotation marks. The "escape" character (always a ^ in Microsoft's CMD, by default a ^ unless changed in 4NT) used in front of a metacharacter also prevents that metacharacter from having its usual effect on command syntax. The "escape" character itself is stripped from the command line before it is passed to the command actually being invoked. e.g. The command line echo ^& will invoke the ECHO command passing it the character & as its command tail, rather than split the command line in twain at the & character as would otherwise occur. Syntax Command lines are devolved into a sequence of commands according to a syntax. In that syntax, simple commands may be combined to form pipelines, which may in turn be combined to form compound commands, which finally may be turned into parenthesized commands. A simple command is just a command name, a command tail, and some redirection specifications. An example of a simple command is dir *.txt > somefile. A pipeline is several simple commands joined together with the "pipe" metacharacter (properly known as the "vertical bar"). The standard output of the simple command preceding each vertical bar is connected to the standard input of the simple command following it, via a pipe. The command interpreter runs all of the simple commands in the pipeline in parallel. An example of a pipeline (comprising two simple commands) is dir *.txt | more. A compound command is a set of pipelines separated by conjunctions. The pipelines are executed sequentially, one after the other, and the conjunction controls whether the command interpreter executes the next pipeline or not. An example of a compound command (comprising two pipelines, which themselves are just simple commands) is move file.txt file.bak && dir > file.txt. The conjunctions are: & The simplest conjunction. The next pipeline is always executed after the current one has completed executing.

Guide to Windows Commands && A positive conditional conjunction. The next pipeline is executed if the current one completes executing with a zero exit status. || A negative conditional conjunction. The next pipeline is executed if the current one completes executing with a non-zero exit status. A parenthesized command is a compound command enclosed in parentheses (i.e. ( and )). From the point of view of syntax, this turns a compound command into a simple command, whose overall output can be redirected. For example: The command line ( pushd temp & dir & popd ) > somefile causes the standard output of the entire compound command ( pushd temp & dir & popd ) to be redirected to somefile. Redirection Redirection specifications are applied, and removed from the command line, before an individual command in a sequence is executed. Redirection specifications control where the standard input, standard output, and standard error file handles for a simple command point. They override any effects to those file handles that may have resulted from pipelining. (See the preceding section on command syntax.) Redirection signs > and >> can be prefixed with 1 for the standard output (same as no prefix) or 2 for the standard error. The redirection specifications are: < filename Redirect standard input to read from the named file. > filename Redirect standard output to write to the named file, overwriting its previous contents. >& filename Join standard output and standard error together and redirect them to write to the named file, overwriting its previous contents. >> filename Redirect standard output to write to the named file, appending to the end of its previous contents. >>& filename Join standard output and standard error together and redirect them to write to the named file, appending to the end of its previous contents.

How a command is executed


(...)

Environment variables
The environment variables of the command interpreter process are inherted by the processes of any (external) commands that it executes. A few environment variables are used by the command interpreter itself. Changing them changes its operation. Environment variables are affected by the SET, UNSET, ESET, PATH, and PROMPT commands. The special variable names in 4NT are not environment variables. They merely have the appearance of them when it comes to variable substitution. They cannot be affected by the aforementioned commands. However, it is possible to create environment variables with the same names as the special variables. In which case the environment variables take precedence during variable substitution. (Creating such environment variables is not recommended. An

Guide to Windows Commands environment variable named %_CWD% is likely to cause confusion and unexpected behaviour in batch files, for example.) The command interpreter inherits its initial set of environment variables from the process that created it. In the case of command interpreters invoked from desktop shortcuts this will be Windows Explorer, for example. Command interpreters generally have textual user interfaces, not graphical ones, and so do not recognize the Windows message that informs applications that the environment variable template in the Registry has been changed. Changing the environment variables in Control Panel will cause Windows Explorer to update its own environment variables from the template in the Registry, and thus change the environment variables that any subsequently invoked command interpreters will inherit. However, it will not cause command interpreters that are already running to update their environment variables from the template in the Registry. COMSPEC The COMSPEC environment variable contains the full pathname of the command interpreter program file. In the case of Microsoft's CMD, this is just inherited from the parent process, and is thus indirectly derived from the setting of COMSPEC in the environment variable template in the Registry. In the case of 4NT, each command interpreter process explicitly sets COMSPEC to name its own program file at startup. So even if the COMSPEC environment variable derived from the template in the Registry names the program file of another command interpreter, from within 4NT, and from within any external commands that it invokes, COMSPEC will always name the program file of 4NT. PATH The value of the PATH environment variable comprises a list of directory names, separated by semi-colon characters. This is the list of directories that are searched, in order, when locating the program file of an external command to execute. PATHEXT The value of the PATHEXT environment variable comprises a list of filename extensions, separated by semi-colon characters. This is the list of filename extensions that are applied, in order, when locating the program file of an external command to execute. PROMPT The value of the PROMPT environment variable controls the text that is emitted whenever the command interpreter displays the prompt (i.e. whenever prompting for a new command line in interactive mode, or whenever echoing a batch file line in batch file mode). Various special character sequences in the value of the PROMPT environment variable cause various special effects when the prompt is displayed, as in the following table:

Guide to Windows Commands

Characters

Microsoft's CMD

4NT

Effect

$$ $A

Yes Yes

Yes Yes

causes the $ character itself to be written out causes a & symbol to be written out (This is a convenience measure, since it is difficult, because it involves quoting, to place a literal & in the value of the PROMPT environment variable using the SET command.) ' (pipe symbol) to be written out Left parenthesis '(' Prints current date ESC (ASCII code 27) Right parenthesis ')' Prints greater-than symbol '>' Backspace (deletes previous character) Prints less-than symbol '<' Prints current drive letter Prints current drive letter and full path Prints '=' (equals sign) Prints ' ' (space character) Prints current system time Prints Windows XP version number Prints <CR> (carriage return character, aka "enter")

$B $C $D $E $F $G $H $L $N $P $Q $S $T $V $_ $+

Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No

Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes

Yes* If command extensions are enabled, prints a number of '+' characters to represent the number of levels pushed on the PUSHD directory stack

This table is incomplete. You can help Wikibooks by expanding it.

Built-in commands
These commands are all built in to the command interpreter itself, and cannot be changed. Sometimes this is because they require access to internal command interpreter data structures, or modify properties of the command interpreter process itself.

Proposed Sections for Commands


Tips and Tricks To make this guide easier to use it is intended to split it into the following sections (Windows XP cmd.exe commands): 2. File and Directory Management ATTRIB - Displays or changes file attributes. CD, CHDIR - Displays the name of or changes the current directory. COPY - Copies one or more files to another location. DEL - Deletes one or more files. DIR - Displays a list of files and subdirectories in a directory. ERASE - Deletes one or more files. MD, MKDIR - Creates a directory.

Guide to Windows Commands MOVE - Moves one or more files from one directory to another directory. RMDIR - Removes a directory. REN, RENAME - Renames a file or files. POPD - Restores the previous value of the current directory saved by PUSHD. PUSHD - Saves the current directory then changes it. RD - Removes a directory. REPLACE - Replaces files. TREE - Graphically displays the directory structure of a drive or path. XCOPY - Copies files and directory trees.

3. File Commands COMP - Compares the contents of two files or sets of files. FC - Compares two files or sets of files, and displays the differences between them. FIND - Searches for a text string in a file or files. FINDSTR - Searches for strings in files. MORE - Displays output one screen at a time. PRINT - Prints a text file. SORT - Sorts input.

TYPE - Displays the contents of a text file. 4. Environment Commands ASSOC - Displays or modifies file extension associations. AT - Schedules commands and programs to run on a computer. DATE - Displays or sets the date. FTYPE - Displays or modifies file types used in file extension associations. LABEL - Creates, changes, or deletes the volume label of a disk. PATH - Displays or sets a search path for executable files. SET - Displays, sets, or removes Windows environment variables. SUBST - Associates a path with a drive letter. TIME - Displays or sets the system time. VER - Displays the Windows version. VOL - Displays a disk volume label and serial number.

Batch File Scripting CALL - Calls one batch program from another. CMD - Starts a new instance of the Windows command interpreter. ECHO - Displays messages, or turns command echoing on or off. ENDLOCAL - Ends localization of environment changes in a batch file. EXIT - Quits the CMD.EXE program (command interpreter). FOR - Runs a specified command for each file in a set of files. GOTO - Directs the Windows command interpreter to a labeled line in a batch program. IF - Performs conditional processing in batch programs. PAUSE - Suspends processing of a batch file and displays a message. REM - Records comments (remarks) in batch files or CONFIG.SYS. SETLOCAL - Begins localization of environment changes in a batch file. SHIFT - Shifts the position of replaceable parameters in batch files. START - Starts a separate window to run a specified program or command.

Interactive Commands CLS - Clears the screen.

Guide to Windows Commands COLOR - Sets the default console foreground and background colors. DOSKEY - Edits command lines, recalls Windows commands, and creates macros. HELP - Provides Help information for Windows commands. PROMPT - Changes the Windows command prompt. TITLE - Sets the window title for a CMD.EXE session.

Other BREAK - Sets or clears extended CTRL+C checking. CACLS - Displays or modifies access control lists (ACLs) of files. CHCP - Displays or sets the active code page number. CHKDSK - Checks a disk and displays a status report. CHKNTFS - Displays or modifies the checking of disk at boot time. COMPACT - Displays or alters the compression of files on NTFS partitions. CONVERT - Converts FAT volumes to NTFS. You cannot convert the current drive. DISKCOMP - Compares the contents of two floppy disks. DISKCOPY - Copies the contents of one floppy disk to another. FORMAT - Formats a disk for use with Windows. GRAFTABL - Enables Windows to display an extended character set in graphics mode.

MODE - Configures a system device. RECOVER - Recovers readable information from a bad or defective disk. VERIFY - Tells Windows whether to verify that your files are written correctly to a disk.

?
ReactOS CMD, 4NT Description This command displays the list of built-in commands.

ACTIVATE
4NT Description This command activates a given window.

ALIAS
4NT

Guide to Windows Commands Synopsys ALIAS /? ALIAS ALIAS name ALIAS name=value

Description This command displays or sets aliases. In the second form, it writes the current list of aliases (in "name=value" form) to standard output. In the third form, it writes the value (only) of the named alias to standard output. In the fourth form, it modifies or creates the alias name assigning it the value value.

ATTRIB
4NT Synopsys ATTRIB /? ATTRIB ATTRIB search-wildcards ATTRIB modifications search-wildcards Modification instructions: To add an attribute attach a '+' in front of it. To remove an attribute attach a '-' in front of it Attributes include A - Archived H - Hidden S - System R - Read-only

Description This command displays or sets file attributes. With no arguments, it displays the attributes of all files in the current directory. With no attribute modification instructions, it displays the attributes of the files and directories that match the given search wildcard specifications. Compare chmod.

Command Cross Reference

Guide to Windows Commands

10

Command

cmd.exe

4NT

ReactOS CMD YES NO YES YES YES NO

Description

Module

? /* ALIAS ASSOC ATTRIB BATCOMP

NO NO NO YES NO NO

YES YES YES YES YES YES

Display internal commands. Process the file as a REXX script. Create "DOSKEY"-like macros in memory Associates an extension with a file type (FTYPE) Displays or changes file attributes. This command compresses batch files into a pre-tokenized form. Start the 4NT debugger

BDEBUGGER BEEP BREAK CALCS

NO NO YES NO

YES YES YES NO

NO YES NO NO

Sets or clears extended CTRL+C checking. Displays or modifies access control lists (ACLs) of files. (External) Calls one batch program from another. This command cancels the execution of all batch files. EXIT/B This command displays or sets the current directory. File and Directory Management Batch File Scripting

CALL CANCEL CD, CHDIR

YES NO YES

YES YES YES

YES NO YES

CHCP CHOICE

YES NO

YES YES

YES NO

Displays or sets the active code page number. Provide user choice to error-level Choice.exe is in the Resource Kit Interactive Commands Interactive Commands File and Directory Management

CLS COLOR COPY

YES YES YES

YES YES YES

YES YES YES

This command clears the screen. Sets the default console foreground and background colors. This command copies files.

DATE DEL, ERASE DIR ECHO ENDLOCAL EXIT EXTPROC FOR FREE FTYPE HELP IF LABEL MD, MKDIR

YES YES YES YES YES YES NO YES NO YES NO YES NO YES

YES YES YES YES YES YES YES YES YES YES YES YES NO YES

YES YES YES YES YES YES NO YES YES NO YES YES YES YES

Display and set the system date Deletes one or more files. Displays a list of files and subdirectories in a directory. Displays messages, or turns command echoing on or off. Ends localization of environment changes in a batch file. Quits the CMD.EXE program (command interpreter). Passes the batch to an external processor (e.g. /#) Runs a specified command for each file in a set of files. Returns the amount of free space on a drive. Sets the file type command. Provides Help information for Windows commands. Performs conditional processing in batch programs. Display or changes the system label Creates a directory. File and Directory Management

MOVE

YES

YES

YES

Moves a file to a new location

Guide to Windows Commands

11
YES YES YES Sets or modifies the PATH environment Causes the command session to pause for user input. Changes to the drive and directory poped from the directory stack Sets or modifies the string displayed when waiting for input. Pushes the current directory onto the stack, and changes to the new directory. Removes the directory. A comment command. Unlike double-colon (::), the command can be executed. Renames a file or directory

PATH PAUSE POPD

YES YES YES

YES YES YES

Prompt PUSHD

YES YES

YES YES

YES YES

RD / RMDIR REM

YES YES

YES YES

YES YES

REN / RENAME SCREEN SET SETLOCAL SHIFT START TIME TIMER TITLE TYPE VER VERIFY VOL

YES

YES

YES

NO YES YES YES YES YES NO YES YES YES YES YES

YES YES YES YES YES YES YES YES YES YES YES YES

YES YES YES YES YES YES YES YES YES YES YES YES

Moves cursor to row, col, and prints text. Sets or displays shell environment variables Creates a child-environment for the batch file. Moves the batch parameters forward. Starts a program with various options. Displays or sets the system clock Starts or stops a stopwatch to time processes. Change the window title Print the content of a file to the console. Show the command processor, operating system versions. Verify that file copy has been done correctly Shows the label of the current volume.

CDD
ReactOS CMD, 4NT Synopsys CDD /? CDD path CDD drive:path Description This command sets the current drive and the current directory of the command interpreter process (and thus the current directory that all external commands will inherit). In the second form, it changes the current directory on the current drive to path. In the third form, it changes the current directory on the specified drive to path, and changes the current drive to that drive.

Guide to Windows Commands

12

DDEEXEC
4NT

DELAY
4NT Description This command pauses execution for a specified period.

DESCRIBE
4NT Description This command displays or sets file descriptions.

DETACH
4NT DIR: Microsoft's CMD, ReactOS CMD, 4NT

DIRHISTORY
4NT

DIRS
ReactOS CMD, 4NT Description This command displays the directory stack, maintained by the PUSHD and POPD commands.

DO
4NT Description This command causes execution to loop.

DRAWBOX
4NT Description This command draws a box on the screen.

DRAWHLINE
4NT

Guide to Windows Commands Description This command draws a horizontal line on the screen. DRAWHLINE

13

DRAWVLINE
4NT Description This command draws a vertical line on the screen.

ECHOERR
4NT Reactos CMD Description This command writes a message to standard error with a newline afterwards.

ECHOS
4NT, Reactos CMD Description This command writes a message to standard output, without adding a newline afterwards.

ECHOSERR
4NT, Reactos CMD Description This command writes a message to standard error, without adding a newline afterwards.

ESET
4NT Description This command allows the user to interactively edit and set environment variables.

EVENTLOG
4NT Description This command adds entries to the Windows event log.

EXCEPT
4NT

FFIND
4NT

Guide to Windows Commands Description This command finds files, or searches files for text strings.

14

FOR
Microsoft's CMD, ReactOS CMD, 4NT Description This command iterates over a series of values, executing a command. Runs a specified command for each file in a set of files. FOR %variable IN (set) DO command [command-parameters] %variable Specifies (set) Specifies command Specifies command-parameters Specifies a single letter replaceable parameter. a set of one or more files. Wildcards may be used the command to carry out for each file. parameters or switches for the specified command.

To use the FOR command in a batch program, specify %%variable instead of %variable. Variable names are case sensitive, so %i is different from %I. If Command Extensions are enabled, the following additional forms of the FOR command are supported: FOR /D %variable IN (set) DO command [command-parameters] If set contains wildcards, then specifies to match against directory names instead of file names. FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters] Walks the directory tree rooted at [drive:]path, executing the FOR statement in each directory of the tree. If no directory specification is specified after /R then the current directory is assumed. If set is just a single period (.) character then it will just enumerate the directory tree. FOR /L %variable IN (start,step,end) DO command [command-parameters] The set is a sequence of numbers from start to end, by step amount. So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would generate the sequence (5 4 3 2 1) FOR /F ["options"] %variable IN (file-set) DO command [command-parameters FOR /F ["options"] %variable IN ("string") DO command [command-parameters FOR /F ["options"] %variable IN ('command') DO command [command-parameter or, if usebackq option present: FOR /F ["options"] %variable IN (file-set) DO command [command-parameters FOR /F ["options"] %variable IN ('string') DO command [command-parameters FOR /F ["options"] %variable IN (`command`) DO command [command-parameter filenameset is one or more file names. Each file is opened, read and processed before going on to the next file in filenameset.

Guide to Windows Commands Processing consists of reading in the file, breaking it up into individual lines of text and then parsing each line into zero or more tokens. The body of the for loop is then called with the variable value(s) set to the found token string(s). By default, /F passes the first blank separated token from each line of each file. Blank lines are skipped. You can override the default parsing behavior by specifying the optional "options" parameter. This is a quoted string which contains one or more keywords to specify different parsing options. The keywords are: eol=c skip=n delims=xxx tokens=x,y,m-n - specifies an end of line comment character (just one) - specifies the number of lines to skip at the beginning of the file. - specifies a delimiter set. This replaces the default delimiter set of space and tab. - specifies which tokens from each line are to be passed to the for body for each iteration. This will cause additional variable names to be allocated. The m-n form is a range, specifying the mth through the nth tokens. If the last character in the tokens= string is an asterisk, then an additional variable is allocated and receives the remaining text on the line after the last token parsed. - specifies that the new semantics are in force, where a back quoted string is executed as a command and a single quoted string is a literal string command and allows the use of double quotes to quote file names in filenameset.

15

usebackq

Some examples might help: FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k would parse each line in myfile.txt, ignoring lines that begin with a semicolon, passing the 2nd and 3rd token from each line to the for body, with tokens delimited by commas and/or spaces. Notice the for body statements reference %i to get the 2nd token, %j to get the 3rd token, and %k to get all remaining tokens after the 3rd. For file names that contain spaces, you need to quote the filenames with double quotes. In order to use double quotes in this manner, you als need to use the usebackq option, otherwise the double quotes will be interpreted as defining a literal string to parse. %i is explicitly declared in the for statement and the %j and %k are implicitly declared via the tokens= option. You can specify up to 26 tokens via the tokens= line, provided it does not cause an

Guide to Windows Commands attempt to declare a variable higher than the letter 'z' or 'Z'. Remember, FOR variables are single-letter, case sensitive, global, and you can't have more than 52 total active at any one time. You can also use the FOR /F parsing logic on an immediate string, by making the filenameset between the parenthesis a quoted string, using single quote characters. It will be treated as a single line of input from a file and parsed. Finally, you can use the FOR /F command to parse the output of a command. You do this by making the filenameset between the parenthesis a back quoted string. It will be treated as a command line, which is passed to a child CMD.EXE and the output is captured into memory and parsed as if it was a file. So the following example: FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i would enumerate the environment variable names in the current environment. In addition, substitution of FOR variable references has been enhanced. You can now use the following optional syntax: %~I %~fI %~dI %~pI %~nI %~xI %~sI %~aI %~tI %~zI %~$PATH:I expands %I removing any surrounding quotes (") expands %I to a fully qualified path name expands %I to a drive letter only expands %I to a path only expands %I to a file name only expands %I to a file extension only expanded path contains short names only expands %I to file attributes of file expands %I to date/time of file expands %I to size of file searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string

16

The modifiers can be combined to get compound results: %~dpI %~nxI %~fsI %~dp$PATH:I expands %I to a drive letter and path only expands %I to a file name and extension only expands %I to a full path name with short names only searches the directories listed in the PATH environment variable for %I and expands to the drive letter and path of the first one found. - expands %I to a DIR like output line

%~ftzaI

Guide to Windows Commands In the above examples %I and PATH can be replaced by other valid values. The %~ syntax is terminated by a valid FOR variable name. Picking upper case variable names like %I makes it more readable and avoids confusion with the modifiers, which are not case sensitive.

17

FREE
4NT, Reactos CMD Description This command displays the free space on a drive.

FTYPE
4NT, Microsoft CMD Description This command displays or sets the command to be executed for a file type.

FUNCTION
4NT

GLOBAL
4NT Description This command searches for directories and executes a command with the current directory set to each directory. ===================

GOSUB
4NT

HEAD
4NT This command transfers control to a subroutine within a batch file, so that control can later be transferred back by RETURN.

Guide to Windows Commands

18

HEAD
4NT
HELP YES YES ? This command invokes the on-line help.

HISTORY
ReactOS CMD, 4NT

IF
Microsoft's CMD, ReactOS CMD, 4NT Description This command conditionally executes a command. Documentation is available by entering IF /? to CMD prompt. What is not documented is that the IF command barfs when it encounters a string containing a '/' character. This can be very frustrating when you need to process a line with this fairly common character that should never be excluded. The problem no doubt comes from the IF command confusing the '/' as part of a /I (or /?) directive on the IF command line.

IFF
4NT Description This command conditionally executes one or more commands, spread across multiple lines.

IFTP
4NT

INKEY
4NT Description This command waits for a key to be pressed.

Guide to Windows Commands

19

INPUT
4NT Description This command prompts the user for input.

KEYBD
4NT

KEYS
4NT

KEYSTACK
4NT Description This command sends keyboard input to other processes on the same desktop.

LIST
4NT Description This command displays the contents of files using a full-screen interactive text user interface.

LOADBTM
4NT Description This command controls whether batch files are completely loaded into memory before execution.

LOG
4NT Description This command controls command logging.

MEMORY
4NT Description This command displays information about available memory.

MKLNK
4NT

Guide to Windows Commands Description This command creates NTFS hard links. Reactos CMD has MKLINK.
MOVE YES YES YES This command moves files. File and Directory Management

20

ON
4NT

OPTION
4NT Description This command invokes the interactive configuration utility or allows configuration options to be altered non-interactively.

PATH
Microsoft's CMD, ReactOS CMD, 4NT Description This command displays or sets the value of the PATH environment variable.

PAUSE
Microsoft's CMD, ReactOS CMD, 4NT Description This command prompts the user and waits for a line of input to be entered.

PDIR
4NT Description This command lists directories in a user-controlled format.

PLAYAVI
4NT

PLAYSOUND
4NT

Guide to Windows Commands

21

POPD
ReactOS CMD, 4NT Description This command removes directories from the directory stack and changes directory.

PRINT
4NT

PROMPT
Microsoft's CMD, ReactOS CMD, 4NT Description The PROMPT command can be used to change or reset the cmd.exe prompt. This command sets the value of the PROMPT environment variable. C:\>PROMPT MyPrompt$G MyPrompt>CD C:\ MyPrompt>PROMPT C:\> The PROMPT command is used to set the prompt to "MyPrompt>". The CD shows that the current directory path is "C:\". Using PROMPT with out any parameters sets the prompt back to the directory path.

PUSHD
ReactOS CMD, 4NT Description This command adds the current directory to the directly stack and changes directory.

QUERYBOX
4NT Description This command displays a query box to the user, prompting for input.

QUIT
4NT

Guide to Windows Commands Description This command terminates the execution of the current batch file.

22

RD
Microsoft's CMD, ReactOS CMD, 4NT Description This command removes directories.

REBOOT
4NT Description This command logs out the current user, and optionally then shuts down, powers off, or reboots the machine.

RECYCLE
4NT Description This command empties the recycle bin.

REN
Microsoft's CMD, ReactOS CMD, 4NT Description This command renames files and directories.

RENAME
Microsoft's CMD, ReactOS CMD, 4NT Description This is an alternative spelling of REN.

REM
Microsoft's CMD, ReactOS CMD, 4NT Description This command does nothing. It is used for remarks in batch files.

RETURN
4NT Description This command returns control from a subroutine in a batch file, returning to the place whence the subroutine was called.

Guide to Windows Commands

23

RMDIR
Microsoft's CMD, ReactOS CMD, 4NT Description This is an alternative spelling of RD.

SCREEN
4NT Description This command moves the cursor to a specified position on the screen, optionally then writing text there.

SCRPUT
4NT Description This command writes text to the screen at a specified position without moving the cursor.

SELECT
4NT Description This command allows the user to interactively select a set of files, and then executes a command against those files.

SENDMAIL
4NT Description This command sends mail.

SET
Microsoft's CMD, ReactOS CMD, 4NT Description This command displays or sets environment variables.

SETDOS
4NT Description This command sets command interpreter control flags.

SETLOCAL
4NT

Guide to Windows Commands

24

SHIFT
Microsoft's CMD, ReactOS CMD, 4NT Description This command shifts the batch file arguments along.

SHORTCUT
4NT Description This command creates shortcuts for Windows Explorer.

SHRALIAS
4NT Description This command controls global alias sharing.

SMPP
4NT

SNPP
4NT

START
Microsoft EXE, 4NT, Reactos CMD Starts in new window. START /LOW program.exe ECHO started, but i am not waiting for finish just starts program.exe with low priority and then immediately follows next command.

SWITCH
4NT

TAIL
4NT

TASKEND
4NT

TASKLIST
4NT Description This command displays the Windows task list.

Guide to Windows Commands

25

TCTOOLBAR
4NT

TEE
4NT Description This command copies what it receives on its standard input to a set of files and to its standard output. It is a "T-piece" for a command pipeline.

TEXT
4NT Description This command displays in-line text contained in batch files.
TIME YES YES YES This command displays or sets the current time.

TIMER
4NT Description This command starts, stops, or displays the current value of one of several stopwatches.

TITLE
4NT Description This command controls the console window title.

TOUCH
4NT Description This command alters the date and time stamps of files and directories.
TREE YES YES ? This command displays the tree structure of directories and files.

Guide to Windows Commands

26

TRUENAME
4NT Description This command displays the true name of a file or directory.
TYPE YES YES YES This command displays the contents of files.

UNALIAS
4NT Description This command deletes aliases.

UNFUNCTION
4NT Description This command deletes functions.

UNSET
4NT Description This command deletes environment variables.
VER YES YES YES This command displays the version number of the command interpreter and the version of Windows.

VERIFY
Microsoft CMD, Reactos CMD, 4NT

Comment
Set or clear the setting to verify whether COPY files etc. are written correctly.

VOL
Microsoft CMD, Reactos CMD, 4NT Description This command displays volume labels.

VSCRPUT
4NT

Guide to Windows Commands Description This command writes text to the screen at a specified position without moving the cursor.

27

WHICH
4NT Description This command displays the locations of other commands.

WINDOW
4NT Description This command alters the size of the console window.

Y
4NT Description This command reads its standard input and a set of files, writing what it reads to its standard output. It is a "Y-piece" for a command pipeline.

External commands
These commands are separate executable program files, supplied with the operating system by Microsoft, or bundled as standard with the third-party command interpreters. By replacing the program files, the meanings and functions of these commands can be changed. Many, but not all, external commands support the "/?" convention, causing them to write on-line usage information to their standard output and then to exit with a status code of 0.

4NT
4NT Synopsys 4NT /? 4NT 4NT /C command Description Invoke (another instance of) 4NT.

Guide to Windows Commands

28

CMD
Microsoft, ReactOS Synopsys CMD /? CMD CMD /C command Description Invoke (another instance of) either Microsoft's CMD or the ReactOS CMD.

FIND
Microsoft

IPCONFIG
Microsoft Synopsys Displays Windows IP Configuration. Shows configuration by connection and the name of that connection (i.e. Ethernet adapter Local Area Connection) Below that the specific info pertaining to that connection is displayed such as DNS suffix and ip address and subnet mask. IPCONFIG /? IPCONFIG (...) Description (...)

MORE
Microsoft Internal in 4NT Synopsys MORE /? MORE [/E] MORE [/E] filename

Guide to Windows Commands Description (...)

29

NET
Microsoft Synopsys NET /? NET (...) Description (...)

PING
Microsoft Synopsys PING /? PING address PING hostname Description Send ICMP/IP "echo" packets over the network to the designated address (or the first IP address that the designated hostname maps to via name lookup) and print all responses received.

References
[1] http:/ / help. fdos. org/ en/ index. htm [2] http:/ / fdos. org/ [3] http:/ / fd-doc. sourceforge. net/ spec/ commands. html

Article Sources and Contributors

30

Article Sources and Contributors


Guide to Windows Commands Source: http://en.wikibooks.org/w/index.php?oldid=2053591 Contributors: Adrignola, Alsocal, Avicennasis, Chuckhoffmann, Darklama, Derbeth, Erlyrisa, Jason.Cozens, Kernigh, Lutskovp, Melab, MichaelFrey, Pcu123456789, QuiteUnusual, Remi, Robert Horning, Runningfridgesrule, Thenub314, Uncle G, Wendy.krieger, Whiteknight, 50 anonymous edits

License
Creative Commons Attribution-Share Alike 3.0 Unported //creativecommons.org/licenses/by-sa/3.0/

Вам также может понравиться