Guide to Windows Commands
From Wikibooks, the open-content textbooks collection
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.
First, it describes using command interpreters — how they receive, parse, and process commands from users. Then it describes the various commands available.
[edit] Guides to DOS commands
This book addresses 32-bit Windows NT command interpreters and commands applicable to the WinNT 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 at fdos.org is a fully hypertext help system for FreeDOS commands, written in 2003/2004
- The FreeDOS Spec 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"
-
- DONT TYPE THE QUOTATION MARKS**
[edit] Using command interpreters
(...)
[edit] 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.
[edit] 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.
[edit] Special names
This is a list of the special names and what they expand to:
Name | Replacement Value Used |
---|---|
_CWD | (4NT only)The current working directory, not ending in a slash character if it is not the root directory of the current drive |
_CWDS | (4NT only)The current working directory, guaranteed to end in a slash character |
%CD% | 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.
[edit] 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.
[edit] 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.
- &&
- 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.
[edit] 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:
- <>
- 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.
[edit] How a command is executed
(...)
[edit] 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 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.
[edit] 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.
[edit] 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.
[edit] 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.
[edit] 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:
Characters | Microsoft's CMD | 4NT | Effect |
---|---|---|---|
$$ | Yes | Yes | causes the $ character itself to be written out |
$A | Yes | Yes | 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.) |
$B | Yes | Yes | ' (pipe symbol) to be written out |
$C | Yes | Yes | Left parenthesis '(' |
$D | Yes | Yes | Prints current date |
$E | Yes | Yes | ESC (ASCII code 27) |
$F | Yes | Yes | Right parenthesis ')' |
$G | Yes | Yes | Prints greater-than symbol '>' |
$H | Yes | Yes | Backspace (deletes previous character) |
$L | Yes | Yes | Prints less-than symbol '<' |
$N | Yes | Yes | Prints current drive letter |
$P | Yes | Yes | Prints current drive letter and full path |
$Q | Yes | Yes | Prints '=' (equals sign) |
$S | Yes | Yes | Prints ' ' (space character) |
$T | Yes | Yes | Prints current system time |
$V | Yes | Yes | Prints Windows XP version number |
$_ | Yes | Yes | Prints |
$+ | No | 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.
[edit] Invoking command interpreters
[edit] 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.
[edit] Proposed Sections for Commands
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.
- 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.
- 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.
- 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.
- 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.
- CLS - Clears the screen.
- 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.
[edit] ?
ReactOS CMD, 4NT
[edit] Description
This command displays the list of built-in commands.
[edit] ACTIVATE
4NT
[edit] Description
This command activates a given window.
[edit] ALIAS
4NT
[edit] Synopsys
- ALIAS /?
- ALIAS
- ALIAS name
- ALIAS name=value
[edit] 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.
[edit] ATTRIB
4NT
[edit] 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
[edit] 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.
[edit] Command Cross Reference
Command | cmd.exe | 4NT | ReactOS CMD | Description | Module |
---|---|---|---|---|---|
? | NO | YES | YES | Display internal commands. | |
/* | NO | YES | NO | Process the file as a REXX script. | |
ALIAS | NO | YES | YES | Create "DOSKEY"-like macros in memory | |
ASSOC | YES | YES | YES | Associates an extension with a file type (FTYPE) | |
ATTRIB | NO | YES | YES | Displays or changes file attributes. | |
BATCOMP | NO | YES | NO | This command compresses batch files into a pre-tokenized form. | |
BDEBUGGER | NO | YES | NO | Start the 4NT debugger | |
BEEP | NO | YES | YES | ||
BREAK | YES | YES | NO | Sets or clears extended CTRL+C checking. | |
CALCS | NO | NO | NO | Displays or modifies access control lists (ACLs) of files. (External) | |
CALL | YES | YES | YES | Calls one batch program from another. | Batch File Scripting |
CANCEL | NO | YES | NO | This command cancels the execution of all batch files. EXIT/B | |
CD, CHDIR | YES | YES | YES | This command displays or sets the current directory. | File and Directory Management |
CHCP | YES | YES | YES | Displays or sets the active code page number. | |
CHOICE | NO | YES | NO | Provide user choice to error-level | Choice.exe is in the Resource Kit |
CLS | YES | YES | YES | This command clears the screen. | Interactive Commands |
COLOR | YES | YES | YES | Sets the default console foreground and background colors. | Interactive Commands |
COPY | YES | YES | YES | This command copies files. | File and Directory Management |
DATE | YES | YES | YES | Display and set the system date | |
DEL, ERASE | YES | YES | YES | Deletes one or more files. | |
DIR | YES | YES | YES | Displays a list of files and subdirectories in a directory. | |
ECHO | YES | YES | YES | Displays messages, or turns command echoing on or off. | |
ENDLOCAL | YES | YES | YES | Ends localization of environment changes in a batch file. | |
EXIT | YES | YES | YES | Quits the CMD.EXE program (command interpreter). | |
EXTPROC | NO | YES | NO | Passes the batch to an external processor (eg /#) | |
FOR | YES | YES | YES | Runs a specified command for each file in a set of files. | |
FREE | NO | YES | YES | Returns the amount of free space on a drive. | |
FTYPE | YES | YES | NO | Sets the file type command. | |
HELP | NO | YES | YES | Provides Help information for Windows commands. | |
IF | YES | YES | YES | Performs conditional processing in batch programs. | |
LABEL | NO | NO | YES | Display or changes the system label | |
MD, MKDIR | YES | YES | YES | Creates a directory. | File and Directory Management |
MOVE | YES | YES | YES | Moves a file to a new location | |
PATH | YES | YES | YES | Sets or modifies the PATH environment | |
PAUSE | YES | YES | YES | Causes the command session to pause for user input. | |
POPD | YES | YES | YES | Changes to the drive and directory poped from the directory stack | |
Prompt | YES | YES | YES | Sets or modifies the string displayed when waiting for input. | |
PUSHD | YES | YES | YES | Pushes the current directory onto the stack, and changes to the new directory. | |
RD / RMDIR | YES | YES | YES | Removes the directory. | |
REM | YES | YES | YES | A comment command. Unlike double-colon (::), the command can be executed. | |
REN / RENAME | YES | YES | YES | Renames a file or directory | |
SCREEN | NO | YES | YES | Moves cursor to row, col, and prints text. | |
SET | YES | YES | YES | Sets or displays shell environment variables | |
SETLOCAL | YES | YES | YES | Creates a child-environment for the batch file. | |
SHIFT | YES | YES | YES | Moves the batch parameters forward. | |
START | YES | YES | YES | Starts a program with various options. | |
TIME | YES | YES | YES | Displays or sets the system clock | |
TIMER | NO | YES | YES | Starts or stops a stopwatch to time processes. | |
TITLE | YES | YES | YES | Change the window title | |
TYPE | YES | YES | YES | Print the content of a file to the console. | |
VER | YES | YES | YES | Show the command processor, operating system versions. | |
VERIFY | YES | YES | YES | Verify that file copy has been done correctly | |
VOL | YES | YES | YES | Shows the label of the current volume. |
[edit] CDD
ReactOS CMD, 4NT
[edit] Synopsys
- CDD /?
- CDD path
- CDD drive:path
[edit] 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.
[edit] DDEEXEC
4NT
[edit] DELAY
4NT
[edit] Description
This command pauses execution for a specified period.
[edit] DESCRIBE
4NT
[edit] Description
This command displays or sets file descriptions.
[edit] DETACH
4NT
DIR: Microsoft's CMD, ReactOS CMD, 4NT
[edit] DIRHISTORY
4NT
[edit] DIRS
ReactOS CMD, 4NT
[edit] Description
This command displays the directory stack, maintained by the PUSHD and POPD commands.
[edit] DO
4NT
[edit] Description
This command causes execution to loop.
[edit] DRAWBOX
4NT
[edit] Description
This command draws a box on the screen.
[edit] DRAWHLINE
4NT
[edit] Description
This command draws a horizontal line on the screen. DRAWHLINE
[edit] DRAWVLINE
4NT
[edit] Description
This command draws a vertical line on the screen.
[edit] ECHOERR
4NT Reactos CMD
[edit] Description
This command writes a message to standard error with a newline afterwards.
[edit] ECHOS
4NT, Reactos CMD
[edit] Description
This command writes a message to standard output, without adding a newline afterwards.
[edit] ECHOSERR
4NT, Reactos CMD
[edit] Description
This command writes a message to standard error, without adding a newline afterwards.
[edit] ESET
4NT
[edit] Description
This command allows the user to interactively edit and set environment variables.
[edit] EVENTLOG
4NT
[edit] Description
This command adds entries to the Windows event log.
[edit] EXCEPT
4NT
[edit] FFIND
4NT
[edit] Description
This command finds files, or searches files for text strings.
[edit] FOR
Microsoft's CMD, ReactOS CMD, 4NT
[edit] 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 a single letter replaceable parameter.
(set) Specifies a set of one or more files. Wildcards may be used
command Specifies the command to carry out for each file.
command-parameters
Specifies 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.
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 - specifies an end of line comment character
(just one)
skip=n - specifies the number of lines to skip at the
beginning of the file.
delims=xxx - specifies a delimiter set. This replaces the
default delimiter set of space and tab.
tokens=x,y,m-n - 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.
usebackq - 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.
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
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 - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - 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
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
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.
[edit] FREE
4NT, Reactos CMD
[edit] Description
This command displays the free space on a drive.
[edit] FTYPE
4NT, Microsoft CMD
[edit] Description
This command displays or sets the command to be executed for a file type.
[edit] FUNCTION
4NT
[edit] GLOBAL
4NT
[edit] Description
This command searches for directories and executes a command with the current directory set to each directory.
[edit] =======
[edit] GOSUB
4NT
[edit] Description
[edit] HEAD
4NT
This command transfers control to a subroutine within a batch file, so that control can later be transferred back by RETURN.
[edit] HEAD
4NT
HELP | YES | YES | ? | This command invokes the on-line help. |
[edit] HISTORY
ReactOS CMD, 4NT
[edit] IF
Microsoft's CMD, ReactOS CMD, 4NT
[edit] 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.
[edit] IFF
4NT
[edit] Description
This command conditionally executes one or more commands, spread across multiple lines.
[edit] IFTP
4NT
[edit] INKEY
4NT
[edit] Description
This command waits for a key to be pressed.
[edit] INPUT
4NT
[edit] Description
This command prompts the user for input.
[edit] KEYBD
4NT
[edit] KEYS
4NT
[edit] KEYSTACK
4NT
[edit] Description
This command sends keyboard input to other processes on the same desktop.
[edit] LIST
4NT
[edit] Description
This command displays the contents of files using a full-screen interactive text user interface.
[edit] LOADBTM
4NT
[edit] Description
This command controls whether batch files are completely loaded into memory before execution.
[edit] LOG
4NT
[edit] Description
This command controls command logging.
[edit] MEMORY
4NT
[edit] Description
This command displays information about available memory.
[edit] MKLNK
4NT
[edit] Description
This command creates NTFS hard links. Reactos CMD has MKLINK.
MOVE | YES | YES | YES | This command moves files. | File and Directory Management |
[edit] ON
4NT
[edit] OPTION
4NT
[edit] Description
This command invokes the interactive configuration utility or allows configuration options to be altered non-interactively.
[edit] PATH
Microsoft's CMD, ReactOS CMD, 4NT
[edit] Description
This command displays or sets the value of the PATH environment variable.
[edit] PAUSE
Microsoft's CMD, ReactOS CMD, 4NT
[edit] Description
This command prompts the user and waits for a line of input to be entered.
[edit] PDIR
4NT
[edit] Description
This command lists directories in a user-controlled format.
[edit] PLAYAVI
4NT
[edit] PLAYSOUND
4NT
[edit] POPD
ReactOS CMD, 4NT
[edit] Description
This command removes directories from the directory stack and changes directory.
[edit] PRINT
4NT
[edit] PROMPT
Microsoft's CMD, ReactOS CMD, 4NT
[edit] 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.
[edit] PUSHD
ReactOS CMD, 4NT
[edit] Description
This command adds the current directory to the directly stack and changes directory.
[edit] QUERYBOX
4NT
[edit] Description
This command displays a query box to the user, prompting for input.
[edit] QUIT
4NT
[edit] Description
This command terminates the execution of the current batch file.
[edit] RD
Microsoft's CMD, ReactOS CMD, 4NT
[edit] Description
This command removes directories.
[edit] REBOOT
4NT
[edit] Description
This command logs out the current user, and optionally then shuts down, powers off, or reboots the machine.
[edit] RECYCLE
4NT
[edit] Description
This command empties the recycle bin.
[edit] REN
Microsoft's CMD, ReactOS CMD, 4NT
[edit] Description
This command renames files and directories.
[edit] RENAME
Microsoft's CMD, ReactOS CMD, 4NT
[edit] Description
This is an alternative spelling of REN.
[edit] REM
Microsoft's CMD, ReactOS CMD, 4NT
[edit] Description
This command does nothing. It is used for remarks in batch files.
[edit] RETURN
4NT
[edit] Description
This command returns control from a subroutine in a batch file, returning to the place whence the subroutine was called.
[edit] RMDIR
Microsoft's CMD, ReactOS CMD, 4NT
[edit] Description
This is an alternative spelling of RD.
[edit] SCREEN
4NT
[edit] Description
This command moves the cursor to a specified position on the screen, optionally then writing text there.
[edit] SCRPUT
4NT
[edit] Description
This command writes text to the screen at a specified position without moving the cursor.
[edit] SELECT
4NT
[edit] Description
This command allows the user to interactively select a set of files, and then executes a command against those files.
[edit] SENDMAIL
4NT
[edit] Description
This command sends mail.
[edit] SET
Microsoft's CMD, ReactOS CMD, 4NT
[edit] Description
This command displays or sets environment variables.
[edit] SETDOS
4NT
[edit] Description
This command sets command interpreter control flags.
[edit] SETLOCAL
4NT
[edit] SHIFT
Microsoft's CMD, ReactOS CMD, 4NT
[edit] Description
This command shifts the batch file arguments along.
[edit] SHORTCUT
4NT
[edit] Description
This command creates shortcuts for Windows Explorer.
[edit] SHRALIAS
4NT
[edit] Description
This command controls global alias sharing.
[edit] SMPP
4NT
[edit] SNPP
4NT
[edit] 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.
[edit] SWITCH
4NT
[edit] TAIL
4NT
[edit] TASKEND
4NT
[edit] TASKLIST
4NT
[edit] Description
This command displays the Windows task list.
[edit] TCTOOLBAR
4NT
[edit] TEE
4NT
[edit] 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.
[edit] TEXT
4NT
[edit] Description
This command displays in-line text contained in batch files.
TIME | YES | YES | YES | This command displays or sets the current time. |
[edit] TIMER
4NT
[edit] Description
This command starts, stops, or displays the current value of one of several stopwatches.
[edit] TITLE
4NT
[edit] Description
This command controls the console window title.
[edit] TOUCH
4NT
[edit] 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. |
[edit] TRUENAME
4NT
[edit] Description
This command displays the true name of a file or directory.
TYPE | YES | YES | YES | This command displays the contents of files. |
[edit] UNALIAS
4NT
[edit] Description
This command deletes aliases.
[edit] UNFUNCTION
4NT
[edit] Description
This command deletes functions.
[edit] UNSET
4NT
[edit] 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. |
[edit] VERIFY
Microsoft CMD, Reactos CMD, 4NT
[edit] Comment
Set or clear the setting to verify whether COPY files etc are written correctly.
[edit] VOL
Microsoft CMD, Reactos CMD, 4NT
[edit] Description
This command displays volume labels.
[edit] VSCRPUT
4NT
[edit] Description
This command writes text to the screen at a specified position without moving the cursor.
[edit] WHICH
4NT
[edit] Description
This command displays the locations of other commands.
[edit] WINDOW
4NT
[edit] Description
This command alters the size of the console window.
[edit] Y
4NT
[edit] 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.
[edit] 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.
[edit] 4NT
4NT
[edit] Synopsys
- 4NT /?
- 4NT
- 4NT /C command
[edit] Description
Invoke (another instance of) 4NT.
[edit] CMD
Microsoft, ReactOS
[edit] Synopsys
- CMD /?
- CMD
- CMD /C command
[edit] Description
Invoke (another instance of) either Microsoft's CMD or the ReactOS CMD.
[edit] FIND
Microsoft
[edit] IPCONFIG
Microsoft
[edit] 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
(...)
[edit] Description
(...)
[edit] MORE
Microsoft Internal in 4NT
[edit] Synopsys
- MORE /?
- MORE [/E]
- MORE [/E] filename
[edit] Description
(...)
[edit] NET
Microsoft
[edit] Synopsys
- NET /?
- NET
(...)
[edit] Description
(...)
[edit] PING
Microsoft
[edit] Synopsys
- PING /?
- PING address
- PING hostname
[edit] 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.
Subjects: Books to be broken into subpages | Guide to Windows Commands | Microsoft Windows
No hay comentarios:
Publicar un comentario