Windows
Commands
Entering
Commands
• Command
options are generally preceded by a forward slash
• Multiple
commands may be concatenated by an ampersand: command1 &
command2.
The commands are executed in sequence.
• Commands
may be executed conditionally, based on the success or failure of a
preceding
command, by joining them with && or || (respectively).
I/O
Redirection
<
file, > file, 1> file, >> file, 1>> file, 2 >
file, 2 >> file, > file 2 >&1
command1
| command2, command1 0 > command2
Form
a pipe, linking the standard output of command1 to the standard input
of
command2.
Environment
Variables
Environment
variables are dereferenced by enclosing the name between percent
signs.
PATH,
PROGRAMFILES, SYSTEMROOT, TEMP and TMP.
Help
Commands
help
command, command /?
net
help command
Obtain
help for one of the net commands.
net
helpmsg nnnn
Explain
Windows 2000 message number nnnn.
cmd
[options] [ /C | /K [ /S ] command]
Start
a new Windows 2000 command interpreter. If command is specified, that
command is
executed.
date
[mm-dd-[yy]yy] [/T] The /T option displays the date without
modifying it.
doskey
[options]
Recall
previous commands or create macros (aliases).
/HISTORY
Display the entire command history list.
/LISTSIZE=n
Set the size of the history list to n.
find
[options] string [files]
/V
Display only nonmatching lines.
/I
Perform a case-insensitive search
/C
Display a count of matching lines only.
/N
Display the line number preceding each line.
findstr
[options] /C:string | /G:file | strings [files]
/R
Interpret search strings as regular expressions.
/L
Interpret search strings as literal text.
logoff
/F /N End the current logon session, suppressing all confirmation
prompts.
more
[options] [files]
/C
Clear the screen before displaying the first page.
/S
Combine (squeeze) multiple blank lines into one.
+n
Begin the display at line n of the input or first file.
now
string Precede the specified string with the current date and time
path
[path] Display or set the search path
sort
[options] [< file]
/R
Reverse usual sort order.
/+n
Start sorting in column n.
time
[hr[:min[:sec[.hd]]]] [A | P] [/T]
title
string Set the title of the current command (cmd.exe) window.
Whoami Display
the username of the currently logged-in user.
assoc
[.ext=filestypename] Associate a file extension with a named file
type.
ftype
[filetypename=command-string]
Display
(no parameters) or define file type-specific command invocations.
net
computer \\host /ADD | /DELETE
Add
or remove the specified computer from the domain database.
net
name [name] [/DELETE]
net
send who message
shutdown
\\remote-host | /L [options] [message]
/R
Reboot after shutting down.
/T:n
Wait n seconds before shutting down (the default is 20).
/Y
Answer yes to all subsequent prompts.
/A
Abort a pending shutdown.
attrib
[options] [files]
Set
DOS file attributes (or display the current attributes if no options
are specified). The file
list
defaults to all files in the current directory.
comp
[options] fileset1 fileset2 Compare two sets of files
compact
[options] [files] Compress or uncompress the specified files
copy
[options] source destination
If
destination is a single file, all source files are concatenated.
del
[options] files Delete files. erase is a synonym for del.
dir
[options] [path]
/S Recurse
subdirectories.
fc
[options] fileset1 fileset2
Compare
files or sets of files, displaying the differences between them. If
multiple source
files
are specified, files of the same name in the second file set are
compared.
move
[/Y] files destination
Move
files to new directory location. Use /Y to suppress overwrite
confirmation prompts.
net
file [id [/CLOSE]]
Without
arguments, list all open shared files and their ID numbers. When an
id is specified,
information
about that item is displayed and the /CLOSE option closes the file.
ren
path new-name Rename the specified file. rename is a synonym
for ren.
replace
source-files destination [options]
Replace/update
files in a destination directory.
/A Add
new files to the destination directory
type
file Display file contents.
xcopy
files destination [options] Copy directory trees.
/EXCLUDE:
file
/S
Recurse nonempty subdirectories.
/E
Include empty directories
/C
Continue copying even if an error occurs.
Working
with Directories
cd
[/D] [path]
Display
or set the current working directory. Use /D to change to the current
directory on the specified drive when it is different from the
current drive.
diruse
[/*] [dirs]
Compute
and display disk space usage by directory for the specified
directories (or the top-
level
folders within the specified directories, if the option is included).
md[mkdir]
path
rd[rmdir]
[options] path
/S
Remove the entire subtree.
tree
dir[options]
Display
the tree structure for the specified directory.
/F
Include filenames in the display.
Working
with Disks and Filesystems
chkdsk
x:[options] Check the filesystem on Drive x.
/F
[/X] Fix any errors encountered. /X forces a volume dismount before
the check.
/R
Locate and recover bad sectors.
diskuse
[path] [options]
Display
disk space usage by user account for the current or specified
directory tree.
format
x: [options]
Format
the disk partition designated by drive letter x (or the diskette in
Drive x:).
label
[x:] [label]
Assign
the volume label for Drive x (defaults to the current drive). If no
label is specified, you
are
prompted for it.
Managing
Shares
net
share share-name[=path] [options] [/DELETE]
Make
a directory available to the network or revoke shared access (the
=path form is used
only
when defining a new shared resource).
Without
arguments, the command lists all currently shared resources.
net
use [device:] [\\host\share] [password | *] [options]
[/DELETE]
Map
a network resource to a local device, which can be a drive letter or
a printer of the form
LPTn.
net
view [target]
Display
the names of the computers in a domain or network, or display the
shared resources
on
a specified remote system.
Printing
con2prt,
lpq, lpr,
print
/D:\\server\ print_share files Print text files on the specified
remote printer.
Networking-Related
Commands
finger
[user][@host] Display information about the specified local or
remote use
ftp
host | IP-address, hostname, telnet
arp Display
and manipulate physical address-IP address translation.
arp
/A [IP-address] [/N interface-address] Display current mapping
arp
/S IP-address physical-address [interface-address]
arp
/D IP-address [interface-address]
ipconfig
[/ALL]
ipconfig
/RENEW | /RELEASE [adapter]
ipconfig
/DISPLAYDNS | /FLUSHDNS
Display
or flush the contents of the DNS resolver cache.
ipconfig
/REGISTERDNS
Reregister
all current DHCP names with the DNS.
net
session [\\host] [/DELETE]
Without
arguments, display session information for all connections to the
local system.
The
/DELETE option causes the specified session or all sessions to
terminate, closing all associated open local files.
net
statistics [SERVER | WORKSTATION]
netsh
[context subcommand ...]
The
network subsystem administration utility. This facility, which can
function either in interactive mode or as a standalone command
utility, provides support for command-line/script-based management of
many network facilities, including DCHP (dhcp context keyword),
network interface (interface), routing (routing), Remote Access
Services (ras), and WINS (wins).
Specify
the primary DNS server for the local system:
netsh
interface ip set dns "Local Area Connection" ^ static
ip-addr
Add
an exclusion range to an existing DHCP scope:
netsh
dhcp server scope name add excluderange ^ ip-addr1 ip-addr2
netstat
[options] [n] /N, /R, /P protocol
nslookup
[host] [DNS server]
Perform
DNS name translation, using the designated DNS server, if specified.
Without options, this command enters interactive mode.
pathping
[options] destination
Trace
routes to the destination, showing the degree of packet loss at each
router/link.
ping
[options] destinations /l length
route
[options] [cmd [dest] [MASK netmask] [gateway] ^ [METRIC hops]]
View
or modify the routing table. cmd is one of the following: PRINT, ADD,
DELETE, CHANGE
/F
Clear all gateway entries from the routing table.
/P
Use with ADD to define a persistent route, which survives system
reboots.
tracert
host | IP-address Display the route to the specified destination.
Administering
Users and Groups
net
accounts /sync
Force
an update of the user accounts database.
net
accounts options [/DOMAIN]
Modify
the system or domain password policy settings.
/MINPWLEN:n,
/MAXPWAGE:n, /MINPWAGE:n, /UNIQUEPW:n
net
localgroup
net
user username [passwd |*] ^ [/ADD [options] | /DELETE]
[/DOMAIN]
Create
or modify user accounts. As indicated, the username can be followed
optionally by a
password
or by an asterisk to request a password promp
Managing
Processes
at List
or schedule delayed and periodic tasks on the specified computer
system.
at
[\\host] job-ID /DELETE
at
[\\host] /DELETE [/YES]
at
[\\host] time [options] command
kill
[/F] item
Memsnap
Write
a listing of all current processes and their memory usage statistics
to the file memsnap.log.
net
print \\host\shared-printer
List
the contents of the specified print queue.
net
print [\\host] job-number [/HOLD | /RELEASE | /DELETE]
pmon
Continuously
display a list of currently running processes, as well as the overall
system memory and paging statistics.
runas
/user:username command Execute a command as the specified user.
start
[window-title] [options] command
/Ddir
Set the current working directory for the command.
/B
Start the command as a background process—don't create a new
window.
net
config [SERVER | WORKSTATION] [options]
Set
configuration information for or display information about the Server
and Workstation services.
net
continue[pause, start, stop] service,
Accessing
the System Registry
reg
op args [options] Perform various registry operations.
netdiag
[options] [/Q | /V | /DEBUG,/FIX]
Test
various aspects of network connectivity for the local server.
netdom
action [options] Manage Windows NT/2000 domains and trust
relationships.
Script-Related
Constructs
:label
%m The
argument number m. (Access arguments above the ninth one via the
shift command.)
%* Corresponds
to all command parameters.
%var
% Value of variable var (local or environment).
Commands
Useful in Scripts
call
file | :label [args]
Run
the specified external script file or labeled subroutine within the
current script.
cls Clear
the screen.
sleep
secs
rem
anything
echo
message
echo
ON | OFF
Enable
or disable command echoing (it is enabled by default).
Pause Pause
execution until the user presses a key.
prompt
text Set the command prompt to text,
$D,
$T Current date, current time.
$G
Greater than sign (>).
$N
Current drive letter.
$P
Current drive and working directory.
set
[var]
Display
the value of the specified variable (or of all defined variables).
set
var=string
Set
the value of a string variable.
set
/A var=numeric-expression
Set
the variable to the result of the evaluated numeric expression.
shift
[/n]
Shift
script or command arguments down one place, starting at argument n
(if specified).
Resources:
Windows
2000 Commands Pocket Reference