Advertisement
dcandygmailcom

Command Prompt Cheat Sheet

Feb 16th, 2019
2,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. Command Prompt Cheat Sheet
  2.  
  3. **CMD Cheat Sheet**
  4.  
  5. First thing to remember its a way of operating a computer. It's the way we did it before WIMP (Windows, Icons, Mouse, Popup menus) became common.
  6.  
  7. **Getting Help**
  8.  
  9. For general help. Type `Help` in the command prompt. For each command listed type `help <command>` (eg `help dir`) or `<command> /?` (eg `dir /?`).
  10.  
  11. Some commands have sub commands. For example `schtasks /create /?`.
  12.  
  13. The `NET` command's help is unusual. Typing `net use /?` is brief help. Type `net help use` for full help. The same applies at the root - `net /?` is also brief help, use `net help`.
  14.  
  15. References in Help to new behaviour are describing changes from CMD in OS/2 and Windows NT4 to the current CMD which is in Windows 2000 and later.
  16.  
  17. --------------------------
  18. **Punctuation**
  19.  
  20. & seperates commands on a line.
  21.  
  22. && executes this command only if previous command's errorlevel is 0.
  23.  
  24. || (not used above) executes this command only if previous command's
  25. errorlevel is NOT 0
  26.  
  27. > output to a file
  28.  
  29. >> append output to a file
  30.  
  31. < input from a file
  32.  
  33. 2> Redirects command error output to the file specified. (0 is StdInput, 1 is StdOutput, and 2 is StdError)
  34.  
  35. 2>&1 Redirects command error output to the same location as command output.
  36.  
  37. | output of one command into the input of another command
  38.  
  39. ^ escapes any of the above, including itself, if needed to be passed
  40. to a program
  41.  
  42. " parameters with spaces must be enclosed in quotes
  43.  
  44. + used with copy to concatinate files. E.G. copy file1+file2 newfile
  45.  
  46. , used with copy to indicate missing parameters. This updates the files
  47. modified date. E.G. copy /b file1,,
  48.  
  49. %variablename% a inbuilt or user set environmental variable
  50.  
  51. !variablename! a user set environmental variable expanded at execution
  52. time, turned with SelLocal EnableDelayedExpansion command
  53.  
  54. %<number> (%1) the nth command line parameter passed to a batch file. %0
  55. is the batchfile's name.
  56.  
  57. %* (%*) the entire command line.
  58.  
  59. %CMDCMDLINE% - expands to the original command line that invoked the
  60. Command Processor (from set /?).
  61.  
  62. %<a letter> or %%<a letter> (%A or %%A) the variable in a for loop.
  63. Single % sign at command prompt and double % sign in a batch file.
  64.  
  65. \\ (\\servername\sharename\folder\file.ext) access files and folders via UNC naming.
  66.  
  67. : (win.ini:streamname) accesses an alternative steam. Also separates drive from rest of path.
  68.  
  69. . (win.ini) the LAST dot in a file path separates the name from extension
  70.  
  71. . (dir .\*.txt) the current directory
  72.  
  73. .. (cd ..) the parent directory
  74.  
  75.  
  76. \\?\ (\\?\c:\windows\win.ini) When a file path is prefixed with \\?\ filename checks are turned off.
  77.  
  78.  
  79.  
  80.  
  81. < > : " / \ | Reserved characters. May not be used in filenames.
  82.  
  83.  
  84.  
  85. Reserved names. These refer to devices eg,
  86.  
  87. copy filename con
  88.  
  89. which copies a file to the console window.
  90.  
  91. CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4,
  92.  
  93. COM5, COM6, COM7, COM8, COM9, LPT1, LPT2,
  94.  
  95. LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9
  96.  
  97. CONIN$, CONOUT$, CONERR$
  98.  
  99. --------------------------------
  100.  
  101. Maximum path length 260 characters
  102. Maximum path length (\\?\) 32,767 characters (approx - some rare characters use 2 characters of storage)
  103. Maximum filename length 255 characters
  104.  
  105. --------------------------------
  106. **Starting a Program**
  107.  
  108.  
  109. See start /? and call /? for help on all three ways.
  110.  
  111. There are two types of Windows programs - console or non console (these are called GUI even if they don't have one). Console programs attach to the current console or Windows creates a new console. GUI programs have to explicitly create their own windows.
  112.  
  113. If a full path isn't given then Windows looks in
  114.  
  115. 1. The directory from which the application loaded.
  116.  
  117. 2. The current directory for the parent process.
  118.  
  119. 3. Windows NT/2000/XP: The 32-bit Windows system directory. Use the
  120. GetSystemDirectory function to get the path of this directory. The
  121. name of this directory is System32.
  122.  
  123. 4. Windows NT/2000/XP: The 16-bit Windows system directory. There is no
  124. function that obtains the path of this directory, but it is
  125. searched. The name of this directory is System.
  126.  
  127. 5. The Windows directory. Use the GetWindowsDirectory function to get
  128. the path of this directory.
  129.  
  130. 6. The directories that are listed in the PATH environment variable.
  131.  
  132. **Specify a program name**
  133. --------------------------
  134.  
  135. This is the standard way to start a program.
  136.  
  137. c:\windows\notepad.exe
  138.  
  139. In a batch file the batch will wait for the program to exit. When
  140. typed the command prompt does not wait for graphical
  141. programs to exit.
  142.  
  143. If the program is a batch file control is transferred and the rest of the calling batch file is not executed.
  144.  
  145. **Use Start command**
  146. --------------------------
  147.  
  148. `Start` starts programs in non standard ways.
  149.  
  150. start "" c:\windows\notepad.exe
  151.  
  152. `Start` starts a program and does not wait. Console programs start in a new window. Using the `/b` switch forces console programs into the same window, which negates the main purpose of Start.
  153.  
  154. Start uses the Windows graphical shell - same as typing in WinKey + R (Run dialog). Try
  155.  
  156. start shell:cache
  157.  
  158. Also program names registered under `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths` can also be typed without specifying a full path.
  159.  
  160. Also note the first set of quotes, if any, MUST be the window title.
  161.  
  162.  
  163. **Use Call command**
  164. -------------------------
  165.  
  166. Call is used to start batch files and wait for them to exit and continue the current batch file.
  167.  
  168.  
  169. --------------------------------
  170. **Keys**
  171.  
  172. **Ctrl + C** exits a program without exiting the console window.
  173.  
  174. For other editing keys type `Doskey /?`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement