Most Windows commands provide switches AKA options to direct their behavior.
Observations:
/
) rather than, as in some other operating systems, with a minus sign (-
).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 as dir /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 of reverse
.
taskkill /im AcroRd32.exe
Taskkill
requires a multi-letter switch name for /im
; shortening to /i
does not work.