Back to List

You are viewing an unformatted version of this file. To get the formatted version, you have to enable JavaScript.
# CMD Basics This document lists basic commands to navigate and use the Windows command line. ## Command line Syntax Arguments are usually enclosed in different types of brackets to show how to use them. Due to how commands envolved, some argument examples can mean multiple things | Example | Description | Alternative usage | |-------------|-------------------------------------|-------------------| | `test` | This word has to appear as-is | Required argument | | `` | This is a required argument | | | `[test]` | This is an optional argument | | | `/{a|b}` | Either /a or /b but not both | | | `[/{a|b}]` | Same as above but optional | | | `[/a|/b]` | Same as above | | | `[...]` | The previous argument is repeatable | | Example on how to read the arguments of the copy command: COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination [/A | /B]] - Required Argument: `source` - Optional arguments before the source: `/D /V /N /Z /L` - Optional arguments before source of which only one can be chosen: `/A` or `/B`, `/Y` or `/-Y` - Optional arguments between source and destination of which only one can be chosen: `/A` or `/B` - Source argument with optional `/A` or `/B` can be repeated but all repetitions must prefix with `+` - Optional destination follows after all sources - Destination can optionally be followed by `/A` or `/B` ## File mask Most commands support file masks to some extent. There are two special characters: - `?` stands for exactly one character. - `*` stands for any number of characters, including zero. Example: `test_???*.txt` will match all files that start with `test_`, followed by 3 or more characters and ending in `.txt`. Masks are limited to the last segment of a path. `C:\???\Test.txt` will usually not work ## `X` vs `x` Windows is a case insensitive operating system by default. The only reason you see commands and arguments written in uppercase is because DOS only used uppercase on the file system. This means you are totally fine to use lowercase if you prefer. ## Redirection Command input and output can be redirected to/from other commands and files. | Example | Meaning | |----------|-----------------------------------------------------------------------------| | `X | Y` | Runs `X`, uses the output of it as input of `Y`. The Output of `Y` is shown | | `X < Y` | Runs `X` and reads content from the file named `Y` instead of the keyboard | | `X > Y` | Runs `X` and writes output to the file `Y`, emptying it before. | | `X >> Y` | Runs `X` and appends the output to the file `Y` | These operations can be combined: `X | Y | Z < A >> B` This will run `X` which reads input from the file `A` and writes output to the Command `Y`. The command `Y` will write the output to the input of command `Z`. `Z` appends the output to the file `B`. ## General Help Most commands support the undocumented `/?` argument which shows usage instructions ## Auto Completion The command prompt supports auto completion for directories and files. Press [`TAB`] repeatedly after typing a few characters to rotate through all matches. You can use [`SHIFT`]+[`TAB`] to go the other direction if you missed an entry. ## Commands The list below contains a few useful commands to get around. ### `HELP` Lists some commands and a short description ### `ECHO` Prints the text after it to console. Useful for scripting ### `X:` Switches the current drive to the one specified ### `CD [[/D] location]` If no arguments are provided, shows the current directory. Changes the active directory to the given location. If `/D` is supplied will also change the active drive if necessary. The location parameter can be absolute or relative. `..` can be supplied as "parent directory" The current directory is accessible as the variable `%CD%` too. ### `DIR` Shows directory listing of all directories and files. Common argument is `/A` to show hidden elements. This command accepts a file mask, for example `C:\Windows\*.exe` will show all executables in the Windows directory and `*.txt` will show all text files in the current directory ### `TYPE ` Dumps the contents of the given file to console. Supports file masks to dump multiple files. ### `COPY` Copies files or concatenates them (if multiple). `COPY *.csv result\result.csv` will concatenate all csv files in the current directory into a single file in the result directory. ### `DEL ` Deletes the given file. Supports file masks ### `MD ` Creates a directory. Multiple levels can be created at once. ### `RD [/S] ` Removes an empty directory. `/S` can be used if it is not empty. ### `SET [Variable[=[Content]]]` - `SET`: Shows all variables - `SET TEST`: Shows all variables beginning with `TEST` - `SET TEST=`: Deletes the variable `TEST` - `SET TEST=A`: Sets the variable `TEST` to `A` Variables are lost as soon as the command prompt is closed. Go to the "Advanced System Properties" to define permanent variables. ### `FIND "string"` Finds contents in the data put into the command and displays the lines containing the search term. The search is case sensitive by default. Example: `SomeCommand | FIND "ERROR:"` will run `SomeCommand` and display only lines containing `ERROR:` ### `CLIP` Store text content in the clipboard. This command has two main usages: - `SomeCommand | CLIP`: Store the output of `SomeCommand` in the clipboard. - `CLIP < File.txt`: Store the contents of `File.txt` in the clipboard. ### `ROBOCOPY` Copies entire directories. Usually used as `ROBOCOPY /MIR `, which will not only copy but also delete everything in destination that no longer exists in source. Essentially makes the contents of "destination" identical to "source".