Most Windows commands provide switches AKA options to direct their behavior.
- Switches most often consist of a single-letter; some switches consist of a sequence of multiple letters.
- Switches are preceded with a slash (
/) rather than, as in some other operating systems, with a minus sign (
- Switches are case-insensitive rather than, as in some other operating systems, case-sensitive.
- If a command from another operating system is ported to Windows (such as
grep), it usually retains the option conventions from the original operating system, including the use of minus sign and case-sensitivity.
Displays the help. This option is provided by many commands.
dir /b /s
Lists all files and folders in the current folder recursively. Two switches are used:
Does not work; switches cannot be accumulated behind a single slash.
findstr /ric:"id: *[0-9]*" File.txt
Unlike many other commands,
findstrallows the accumulation of switches behind a single slash. Indeed, r, i and c are single-letter switches.
dir, removing whitespace between the command and the first switch or between the switches does not make a difference; thus, does the same as
dir /b /s.
Does not work, unlike
tree /f /a. In tree, separation by whitespace is mandatory. Nor does find/i/v work.
The switch letter o is further modified by a single letter specifying that ordering should be by date. The letter d is not a switch by itself. Similar cases include
dir /adand more
dir /B /S
The switches are case-insensitive, unlike in some other operating systems.
sort /r file.txt
Sorts the file in a reverse order.
sort /reverse file.txt
Sort allows the switch string to be longer than a single-letter.
sort /reve file.txt
Sort allows the specified switch string to be a sub-string of the complete long name of the switch. Thus, does the same as the above.
sort /reva file.txt
Does not work, since
revais not a sub-string of
taskkill /im AcroRd32.exe
Taskkillrequires a multi-letter switch name for
/im; shortening to
/idoes not work.
Java, which originated in the environment of another operating system family, uses the minus convention for its switches AKA options.
If GNU grep is installed, it requires multi-letter switches to be preceded by two dashes.