Basic Commands
-E-
ECHO
The ECHO command command window script output, or generates script output to the console window.
Syntax:
1. ECHO
2. ECHO ON|OFF
3. @ECHO %ECHO%
4. ECHO text
When executing a script, the command shell, by default, echoes each executed command in the console window. Use ECHO (2) to enable or disable this feature. Use ECHO (1) to display the current state of the echo toggle.
Script commands that begin with the @ character will not be echoed in the console window, regardless of the state of the echo toggle.
Use ECHO (4) to display text in the console window. To display an empty line, use ECHO. or a single Tab character as text.
See also: TITLE, NOW
ENDLOCAL
The ENDLOCAL command, when used in a script file, ends a local scope for environment variable changes. Any changes made to the environment before a ENDLOCAL command is executed are lost.
Syntax:
ENDLOCAL
See also: SETLOCAL, SET
ERASE
See DEL
EXIT
The EXIT command exits the current command shell, ending the shell session. The program invoking the shell then continues executing. If the command shell exiting is the one that started the console window, the window closes.
Syntax:
EXIT
See also:CMD, COMMAND
-F-
FC
The FC command compares files.
Syntax:
1. FC /L [switches] [drive1:][path]filename1 [drive2:][path2]filename2
2. FC /B [drive1:][path]filename1 [drive2:][path2]filename2
Switches:
| /A |
Display only first and last line for each line found. |
| /B |
Perform binary comparison. |
| /C |
Perform case insensitive comparison. |
| /L |
Compare files in ASCII. |
| /LBn |
Set maximum consecutive matches to n lines. |
| /N |
Display line numbers during comparison. |
| /T |
Do not expand tabs into spaces. |
| /U |
Compare files as Unicode. |
| /W |
Compress white space runs for comparison and ignore leading/trailing whitespace. |
| /nn |
Minimum number of lines that must match after mismatch. |
Files can be compared in two modes: ASCII/Unicode or binary. Use FC(1) to compare file in ASCII or Unicode. Use FC(2) to compare file in binary. If the files being compared have a file extension of .EXE, .COM, .SYS, .OBJ, .LIB, .BIN then the default comparison mode is binary. Otherwise, the default mode is ASCII/Unicode.
See also: MORE, SORT, FINDSTR
FIND
The FIND command filters text files for matching lines.
Syntax:
1. FIND [/V][/C][/N][/I] "string" [drive][path]filename
2. FIND [/V][/C][/N][/I] "string"
Switches:
| /V |
Invert test. Displays lines not matching the string. |
| /C |
Display only the count of matching lines. |
| /N |
Display line numbers of matching lines. |
| /I |
Ignore case when matching line. |
The FIND command searches and filters text. Text lines are matched against the specified string. Those lines that contain the string are displayed. Those that don not are discarded.
Use FIND(1) to filter text from one or more files. The filename can contain wildcards, allowing multiple files to be searched.
Use FIND(2) to filter text from command input. By default, command input is all text typed at the console up to the end of file character, Ctrl+Z. Use the console input redirection symbols to redirect console input from a file or device. Use the pipe command to send the output of any command to the command input of the FIND command for processinf
The /V switch inverts the sense of the string matching. Instead of displaying those lines that conatain the string, the /V switch displays only those lines that do not contain the string. The /C switch displays only a count of the matching lines, rather than the lines themselves. The /N switch prefixes each displayed line with the line number in the text file. The /I switch ignores case differences when searching for string in the input lines.
Example:
dir | find /C "<DIR>"
This command counts the number of subdirectories in the current directory.
See also: MORE, SORT, FINDSTR
FINDSTR
The FINDSTR command searches one or more text files for lines containg one of the specified strings. Normally, FINDSTR displays each matching line.
Syntax:
1. FINDSTR [switches] [/S] strings [drive:][path]filename
2. FINDSTR [switches] /F:file strings
3. FINDSTR [switches] [/S] /C:string [drive:][path]filename
4. FINDSTR [switches] /F:file /C:string
5. FINDSTR [switches] [/S] /G:file [drive:][path]filename
6. FINDSTR [switches] /F:file /G:file
Switches:
| /B |
Matches strings if they occur at the beginning of the line. |
| /E |
Matches strings if they at the end of the line. |
| /X |
Matches strings if they exactly match the line. |
| /L |
Treat strings as literal text. |
| /R |
Treat strings as regular expressions (default). |
| /I |
String matches are case insensitive. |
| /V |
Display lines that do not match the specified strings. |
| /N |
Display the line number before each line. |
| /M |
Display only the filename for each file containing matches. |
| /O |
Display the file offset before each line. |
| /C:string |
Specify a search string. |
| /G:file |
Get search strings from the specified file. |
| /F:file |
Get list of files to search from specified file. |
| /S |
Search all subdirectories of the directoy specified. |
The test specified by string or strings is matched character for character against text in the file being searched. By default, search strings are treated as regular expressions. Rather than matching literally, FINDSTR uses each search string as a template that describes the pattern of text to match. These are shown in the following table:
| . (dot) |
Matches any single character. |
| * |
Matches the previous character or class any number of times (including zero). |
| ^ |
Matches the beginning of the line. Similar in effect to the /B switch. |
| $ |
Matches the end of a line. Similar in effect to the /E switch. |
| [class] |
Matches any character listed between the brackets. |
| [^class] |
Matches any character not listed between the brackets. |
| [x-y] |
Matches any character inn the range x to y. |
| \x |
Escapes the character x to a literal. |
| \< |
Matches the beginning of a word. |
| \> |
Matches the end of a word. |
See also: FIND
FOR
The FOR command iterates files, directories, text file lines, command output and numeric series.
Syntax:
1. FOR [/D] %var IN (set) DO command
2. FOR /R [drive:][path] %var IN (set) DO command
3. FOR /L %var IN (start,step,end) DO command
4. FOR /F ["opts"] %var IN (set) DO command
5. FOR /F ["opts"] %var IN ("string") DO command
6. FOR /F ["opts"] %var IN ('cmd') DO command
Switches:
| /D |
Match directory names instead of filenames. |
| /R |
Recursive directory tree walk. |
| /L |
Iterate a numeric series. |
| /F |
File token parsing. |
For each step in the iteration, the command specified is executed. The iterator variable, %var, is substituded in the command line in a manner similar to that used for parameter substitution. The iterator variable is named using a single letter after the percent, such as %i or %n. Note that the interator variable name is case sensitive.
When placing the FOR command in a script file, double the % on all references to the iterator variable. Thus, use %%n instead of %n within a script file. Do not do this if entering a FOR command directly at the command prompt.
Use FOR(1) to iterate a set of files or directories. set specifies the file to iterate, and must be a filename or a wildcard. You can include a drive letter and path name in set, otherwise the current drive letter and directory is assumed. By default, FOR(1) iterates files. Use the /D switch to iterate directories instead. Parameter qualifiers can be used in %var to access portions of the file or path name being iterated (see "Parameter Syntax").
Use FOR(2) to perform a FOR(1) type iteration on an entire directory tree. Specify a drive and/or path name as the root of the directory tree to iterate following the /R switch. If no drive or path is specified, the current directory is assumed. FOR(2) walks the directory tree specified, executing the FOR command for the specified set in each directory. If set is *.*, all the files in the entire tree are iterated. If set is a single dot, only the directories themselves are iterated.
Use FOR(3) to perform a numeric iteration. The start,step and end values are numeric values specifying the start value, step amount (increment) and end value for the iteration. Start and end values are inclusive. Use an end value less than a start value, along with a negative step value, to perform a descending iteration. The iteration ends when the current iterator value in var exceeds the end value specified.
Use FOR(4), FOR(5) and FOR(6) to parse text files and strings into tokens. FOR(4) processes each file specified in set as a text file, iterating each line in each file. Note that, in this case, set is a set f one or more file names seperated by spaces. Wildcards are not allowed.
FOR(5) processes the text string specified. in this case, the iterated command is called only once, with the results of the parsing in the iterator variable.
FOR(6) processes the output of each command. Enclose cmd in single quotes. The command is executed, and each line of output generated is parsed before command is executed. This form of the FOR command is very useful, as it allows the output of commands to be captured and parsed for further processing. FOR(6) executs the specified cmd to completion before starting the iteration.
To parse a line of text, the FOR command first breaks the line into tokens. A token is a portion of an input line delimited by delimeter characters (such as commas or spaces). By default, tokens are delimited by space or tab characters (but see note below). The tokens are then assigned to the iterator variable or variables. Finally, the specified command is executed. The process then repeats for the next line. Empty lines are skipped (the command is not executed). The parsing and tokenizing operation is controlled by the optional opts. IF present, these must be enclosed in double quots. Individual options in opts are seperated by spaces. The following table shows all available options:
| eol=c |
Specifies and end of line comment delimeter character. |
| skip=n |
Specifies the number of lines to skip at the start of each text file. |
| delims=xxx |
Specifies one or more delimeters to use instead of the default space and tab. |
| tokens=x,y,m-n |
Specifies which tokens on each line are to be placed in variables for iteration. |
See also: For Loops
FSUTIL
File and Volume specific commands, Hardlink management, Quota management, USN, Sparse file, Object ID and Reparse point management. (WinXP/2003)
Creating a hardlink
FSUTIL hardlink create <new filename> <existing filename>
Eg : fsutil hardlink create c:\foo.txt c:\bar.txt
Create a new file of a specific size
FSUTIL file createnew <filename>
Eg : fsutil file createnew C:\testfile.txt 1000
Set the short name for a file
FSUTIL file setshortname <filename> <shortname>
Eg : fsutil file setshortname C:\testfile.txt testfile
Set the valid data length for a file
FSUTIL file setvaliddata <filename> <datalength>
Eg : fsutil file setvaliddata C:\testfile.txt 4096
Set the zero data for a file
FSUTIL file setzerodata offset=<val> length=<val> <filename>
offset : File offset, the start of the range to set to zeroes
length : Byte length of the zeroed range
Eg : fsutil file setzerodata offset=100 length=150 C:\Temp\sample.txt
List all drives (including mapped and Subst drives)
FSUTIL fsinfo drives
Query drive type for a drive
FSUTIL fsinfo drivetype <volume pathname>
Eg : fsutil fsinfo drivetype C:
ListLocalDrives.cmd - List all drives on the local computer
Query volume information
FSUTIL fsinfo volumeinfo <volume pathname>
Eg : fsutil fsinfo volumeinfo C:\
Query NTFS specific volume information
FSUTIL fsinfo ntfsinfo <volume pathname>
Eg : fsutil fsinfo ntfsinfo C:
Query file system statistics
FSUTIL fsinfo statistics <volume pathname>
Eg : fsutil fsinfo statistics C:
QUOTA Management
FSUTIL quota {query|disable|track|enforce } C:
FSUTIL quota violations
FSUTIL quota modify <volume pathname> <threshold> <limit> <user>
Eg : fsutil quota modify c: 3000 5000 domain\user
Find a file by user name (if Disk Quotas are enabled)
FSUTIL file findbysid <user> <directory>
Eg : fsutil file findbysid scottb C:\users
File system options:
FSUTIL behavior query option
FSUTIL behavior set option
FSUTIL dirty query <volume pathname>
FSUTIL dirty set <volume pathname>
Where option is one of:
disable8dot3
allowextchar
disablelastaccess
quotanotify
mftzone
Eg : FSUTIL behavior query disable8dot3 1
FSUTIL dirty query C:
Query a reparse point
FSUTIL reparsepoint query <filename>
Eg : fsutil reparsepoint query C:\Server
Delete a reparse point
FSUTIL reparsepoint delete <filename>
Eg : fsutil reparsepoint delete C:\Server
Edit an object identifier
FSUTIL objectid {query | set | delete | create}
Set sparse file properties
FSUTIL sparse queryflag <filename>
FSUTIL sparse setflag <filename>
FSUTIL sparse queryrange <filename>
FSUTIL sparse setrange <filename>
Eg : fsutil sparse queryflag "C:\My Test.txt"
Query the allocated ranges for a file
FSUTIL file queryallocranges offset=<val> length=<val> <filename>
offset : File Offset, the start of the range to query
length : Size, in bytes, of the range
Eg : fsutil file queryallocranges offset=1024 length=64 C:\Temp\sample.txt
FTP
File Transfer Protocol is used for exactly what the name suggests. Connection to an FTP server can be limited by username and password. FTP communicates over TCP for a reliable transfer mechanism for large files. TFTP is trivial file transfer protocol and this uses UDP at the transport layer. For that reason TFTP is only suitable for small file transfers and is rarely used.
C:\WINDOWS>ftp -help
Transfers files to and from a computer running an FTP server service (sometimes called a daemon). Ftp can be used interactively.
FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [-A] [host]
Options:
| -v |
Suppresses display of remote server responses. |
| -n |
Suppresses auto-login upon initial connection. |
| -i |
Turns off interactive prompting during multiple file transfers. |
| -d |
Enables debugging. |
| -g |
Disables filename globbing (see GLOB command). |
| -s:filename |
Specifies a text file containing FTP commands; the commands will automatically run after FTP starts. |
| -a |
Use any local interface when binding data connection. |
| -A |
login as anonymous. |
| -w:buffersize |
Overrides the default transfer buffer size of 4096. |
| host |
Specifies the host name or IP address of the remote host to connect to. |
FTYPE
The FTYPE command displays and alters file type commands in the registry. Once a file is defined you can use the ASSOC command to associate it with one or more file extensions.
Syntax:
1. FTYPE
2. FTYPE filetype
3. FTYPE filetype=
4. FTYPE filetype=text
Use FTYPE(1) to display all current file types, and FTYPE(2) to display a specific file type. Use FTYPE(3) to delete an existing file type, and FTYPE(4) to create a new type or change an existing type.
The text can be any Windows NT executable program and any additional required parameters (spaces allowed). Always specify the filename of the executable, including the file extension and (typically) the path name. Within the text, use %0 or %1 to represent the name of the file being opened. %2 onwards represents additional arguments aupplied. You can use %* to represent all arguments (from %2 onwards), and %~n to represent all arguments starting at argument n. Generally, %0 or %1 should be enclosed in double quotes to ensure that file names with embedded spaces are correctly processed.
See also: ASSOC, ASSOCIATE
-G-
GLOBAL (Windows NT Resource Kit)
The GLOBAL command displays the member list for a specified global group.
Syntax:
GLOBAL groupname domain|\\computername
See also: LOCAL, IFMEMBER, NET GROUP
GOTO
The GOTO command transfers control to a different location with in the script. GOTO executes a "jump" to the specified location-no automatic return is possible..
Syntax:
1. GOTO [:]label
2. GOTO :EOF
Use GOTO(1) to jump to another location in the current script specified by label. The colon before the label in the GOTO statement is optional. Use GOTO(2) to jump to the end of the current script file. This either terminates the current script or (if the script was invoked in a CALL statement) returns to the calling script.
Example:
goto :exit
.
.
:exit
See also: CALL, LABEL