Switches
suggest changeMost Windows commands provide switches AKA options to direct their behavior.
Observations:
- 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.
Examples:
dir /?
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:
/b
and/s
.dir /bs
Does not work; switches cannot be accumulated behind a single slash.
findstr /ric:"id: *[0-9]*" File.txt
Unlike many other commands,
findstr
allows the accumulation of switches behind a single slash. Indeed, r, i and c are single-letter switches.dir/b/s
Works. In
dir
, removing whitespace between the command and the first switch or between the switches does not make a difference; thus, does the same asdir /b /s
.tree/f/a
Does not work, unlike
tree /f /a
. In tree, separation by whitespace is mandatory. Nor does find/i/v work.dir /od
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 /ad
and more/t4
.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
reva
is not a sub-string ofreverse
.taskkill /im AcroRd32.exe
Taskkill
requires a multi-letter switch name for/im
; shortening to/i
does not work.java -version
Java, which originated in the environment of another operating system family, uses the minus convention for its switches AKA options.
grep --help
If GNU grep is installed, it requires multi-letter switches to be preceded by two dashes.