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 /sLists all files and folders in the current folder recursively. Two switches are used:
/band/s.dir /bsDoes not work; switches cannot be accumulated behind a single slash.
findstr /ric:"id: *[0-9]*" File.txtUnlike many other commands,
findstrallows the accumulation of switches behind a single slash. Indeed, r, i and c are single-letter switches.dir/b/sWorks. 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/aDoes not work, unlike
tree /f /a. In tree, separation by whitespace is mandatory. Nor does find/i/v work.dir /odThe 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/t4.dir /B /SThe switches are case-insensitive, unlike in some other operating systems.
sort /r file.txtSorts the file in a reverse order.
sort /reverse file.txtSort allows the switch string to be longer than a single-letter.
sort /reve file.txtSort 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.txtDoes not work, since
revais not a sub-string ofreverse.taskkill /im AcroRd32.exeTaskkillrequires a multi-letter switch name for/im; shortening to/idoes not work.java -versionJava, which originated in the environment of another operating system family, uses the minus convention for its switches AKA options.
grep --helpIf GNU grep is installed, it requires multi-letter switches to be preceded by two dashes.