Article directory
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 ishelp/get-help <cmd>
or<cmd> /?
, Note: In cmd, pass in parameters It is/xxx
since realized! -
You can completely regard cmd and powershell as a program . Run it in any terminal
cmd
orpowershell
enter the cmd environment or Windows powershell environment. If you want to exit, you can useexit
3 cmd command collection
cmd /c dir
It is to close the command window after executing the dir command.cmd /k dir
It does not close the command window after executing the dir command.cmd /c start dir
A 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 Linuxwhich
, not applicable in powershell!dir
View the files and folders in the current directory, and comparels
the 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 toGet-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 applicabletree
Viewing 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
- How to use variables and functions: use functions
for string execution
If you want to use python to execute commands, the first method is recommended