[Windows] cmd and powershell command collection

1 Introduction

  In the process of daily use, there will always be situations where you can’t remember or can’t distinguish between cmd commands and powershell commands, because most of the work in Windows is visual mouse clicks, and the command line is rarely used, so it’s natural. It is difficult to get familiar with, and cmd is unique to Windows, and although powershell is also a shell, compatible with shell scripts, it is still very different from the command system under Linux, and has many features of Windows, so it is still necessary to make some records .

2 some rules

  When using and understanding related instructions, some basic rules need to be clarified first

  • Instructions in powershell and cmd are not case sensitive

  • Understand the meaning of parentheses in instructions
    When viewing the help documentation for instructions, you will often see some parentheses: [], <>, {}, the meaning of which is:

    • []: Optional
    • <>: Important
    • {}: {a | b},Important and Select one
  • Check how to use a command
      Under Linux, there are two main ways to check how to use a command, that is, man <cmd>or <cmd> --help/-h, in powershell, some of these commands are compatible, but more commonly used is help/get-help <cmd>or <cmd> /?, Note: In cmd, pass in parameters It is /xxxsince realized!

  • You can completely regard cmd and powershell as a program . Run it in any terminal cmdor powershellenter the cmd environment or Windows powershell environment. If you want to exit, you can useexit
    insert image description here

3 cmd command collection

  • cmd /c dirIt is to close the command window after executing the dir command.
  • cmd /k dirIt does not close the command window after executing the dir command.
  • cmd /c start dirA new window will be opened and the dir command will be executed, and the original window will be closed.
  • where <cmd>View the location of a certain command, corresponding to the command in Linux which, not applicable in powershell!
  • dirView the files and folders in the current directory, and compare lsthe commands in powershell and Linux

4 bat grammar learning

Have time to study hard

5 powershell command collection

  • Get-Alias / gal: View the alias of the command, so that when a command is found to be wrong, you can see what command it specifically refers to
  • Get-Command: Get the path where the command is located, corresponding to cmdwhere
  • man: Same as under Linux, it can be used to view the help information of the command, but some instructions are not applicable
  • treeViewing the directory tree is also applicable in cmd, but the functions are relatively scarce. It is recommended to refer to this link to download the software under Linux, which has more complete functions.

6 powershell syntax learning

Have time to study hard

If you want to use python to execute commands, the first method is recommended

Guess you like

Origin blog.csdn.net/ZHOU_YONG915/article/details/131749025