[Powershell] (bajo Windows) comandos comunes | alias de comando | ejecutar herramientas de línea de comandos de Windows | ejecutar programas de usuario (vim, gcc, gdb)

Documentación oficial de Powershell de Microsoft: https://learn.microsoft.com/zh-cn/powershell/

Los detalles del comando están al final del PDF:
inserte la descripción de la imagen aquí


1. Introducción a Powershell y comandos

PowerShell es un shell de línea de comandos y un lenguaje de secuencias de comandos para la automatización .

Wikipedia contiene la siguiente descripción del caparazón:

El shell administra la interacción entre el usuario y el sistema solicitando la entrada del usuario, interpretando su entrada y luego procesando la salida del sistema operativo subyacente (muy parecido a un ciclo de lectura-evaluación-impresión [es decir, REPL]).

Al igual que otros shells como bash o cmd.exe, PowerShell le permite ejecutar cualquier comando disponible en su sistema, no solo los comandos de PowerShell.

Los comandos de PowerShell se llaman cmdlet(command-lets pronunciados). Los cmdlets son comandos de PowerShell, no ejecutables independientes. Los comandos de PowerShell no se pueden ejecutar en otros shells sin ejecutar primero PowerShell.

PowerShell es un shell de comando moderno que incluye las mejores características de otros shells populares. A diferencia de la mayoría de los shells, que solo aceptan y devuelven texto, PowerShell acepta y devuelve .NETobjetos . El shell tiene varias funciones que se pueden usar para optimizar la experiencia interactiva del usuario.

1.1 Formato de comando

Los comandos de PowerShell siguen una convención de nomenclatura específica, el formato "verbo-sustantivo". Esta estructura hace que los comandos sean fáciles de leer y comprender. Los siguientes son los componentes de un cmdlet de PowerShell:

  1. Verbo (Verb) : Describe la acción que realiza el cmdlet. Por ejemplo, Get, Set, New, Removeetc.

  2. Sustantivo (Sustantivo) : Describe el objeto o recurso en el que opera el cmdlet. Por ejemplo, Item, Service, Processetc.

  3. Parámetros : información adicional proporcionada al cmdlet para afectar su funcionamiento. Los parámetros generalmente -comienzan con , por ejemplo -Name, , -Pathetc.

  4. Valores de parámetro (Parameter Values) : el valor específico que sigue al parámetro. Por ejemplo, en Get-Service -Name "wuauserv", "wuauserv"es -Nameel valor del parámetro.

Estos son algunos ejemplos de cmdlets de PowerShell:

  • Get-Service: obtenga una lista de todos los servicios que se ejecutan en el sistema.
  • Get-Process: obtenga una lista de todos los procesos que se están ejecutando actualmente.
  • New-Item: crea un elemento nuevo, como un archivo o una carpeta.
  • Remove-Item: elimina un elemento, como un archivo o una carpeta.

Además, PowerShell admite canalización ( |) para pasar la salida de un cmdlet a otro cmdlet como entrada. Por ejemplo, Get-Process | Where-Object {$_.CPU -gt 100}se recuperan todos los procesos con un uso de CPU superior a 100.

1.2 Alias ​​de comandos

Muchos comandos (cmdlets) en PowerShell tienen alias. Los alias son nombres cortos para uno o más cmdlets que proporcionan una forma rápida de escribir comandos usados ​​con frecuencia sin tener que escribir el nombre completo del cmdlet.

Por ejemplo:

  • Get-CommandEl alias para es gcm.
  • Get-HelpUn alias para es helpo man.
  • Get-ProcessEl alias para es ps.
  • Get-ItemEl alias para es gi.

Puede usar Get-Aliasel cmdlet para ver todos los alias disponibles. Por ejemplo, para ver Get-Commandtodos los alias de , puede ejecutar:

Get-Alias -Definition Get-Command

Si desea ver todos los alias y sus cmdlets correspondientes, simplemente puede ejecutar:

Get-Alias

Además, puede usar Set-Aliascmdlets para crear sus propios alias. Por ejemplo, si desea Get-Servicecrear un alias para gs, puede ejecutar:

Set-Alias -Name gs -Value Get-Service

De esa manera, cada vez que escriba gs, se ejecutará Get-Serviceel cmdlet.

Además, puede usar los comandos de finalización de tabulación.

Dos, alias de cmdlet

Estos alias se obtienen 7.36mediante el uso de comandos en la versión .Get-Alias

Algunos alias pueden ser los mismos que los comandos bash de Linux, pero los parámetros generalmente son diferentes.

Alias Nombre del cmdlet Función descriptiva)
? Donde-Objeto objeto de filtro
% Para cada objeto realizar operaciones en cada objeto
C.A Agregar contenido agregar contenido al archivo
gato Obtener el contenido obtener el contenido del archivo
cd, chdir Escoger localización cambiar la ubicación actual
clc Borrar contenido contenido claro
claro, claro Clear-Host salida clara de la consola
clhy Borrar historial borrar historial de comandos
cli Borrar artículo elemento claro
clp Clear-ItemProperty Borrar propiedades del proyecto
clv Borrar-Variable variable clara
cnsn Conectar-PSSession Conectarse a PSSession
comparar Comparar objeto Comparar objetos
copia, cp, cpi Copiar elemento copiar elemento
cpp Copy-ItemProperty Copiar propiedades del proyecto
cvpa Convert-Path ruta de conversión
dbp Desactivar-PSBreakpoint deshabilitar punto de interrupción
del, erase Remover el artículo Eliminar elemento
diferencia Comparar objeto Comparar objetos
directorio Obtener elemento secundario Obtener una lista de subelementos
DNS Desconectar-PSSession Desconectar PSSession
reflujo Habilitar-PSBreakpoint habilitar punto de interrupción
eco Salida de escritura contenido de salida
Manzana Exportar-Alias exportar alias
epcsv Exportar-Csv exportar a CSV
borrar Remover el artículo Eliminar elemento especificado
no Entrar-PSSession Ingrese PSSession
p.ej Salir-PSSession salir-PSSession
f.c. Formato personalizado formato personalizado
efectos especiales Formato hexadecimal formateado como hexadecimal
Florida Formato-Lista formato de lista
para cada Para cada objeto realizar operaciones en cada objeto
pie Formato-Tabla formato de tabla
adelante Todo el formato formato amplio
galón Obtener alias obtener alias
GBP Obtener PSBreakpoint obtener punto de interrupción
gc Obtener el contenido obtener el contenido
gcb Obtener portapapeles Obtener contenido del portapapeles
gci Obtener elemento secundario obtener subelemento
gcm Obtener comando obtener comando
gcs Obtener PSCallStack obtener pila de llamadas
rda Obtener PSDrive conseguir conducir
levadura Obtener error obtener error
por qué Get-History 获取历史
gi Get-Item 获取项目
gin Get-ComputerInfo 获取计算机信息
gjb Get-Job 获取作业
gl Get-Location 获取当前位置
gm Get-Member 获取成员
gmo Get-Module 获取模块
gp Get-ItemProperty 获取项目属性
gps Get-Process 获取进程
gpv Get-ItemPropertyValue 获取项目属性值
group Group-Object 对象分组
gsn Get-PSSession 获取 PSSession
gsv Get-Service 获取服务
gtz Get-TimeZone 获取时区
gu Get-Unique 获取唯一值
gv Get-Variable 获取变量
h, history Get-History 获取历史
icm Invoke-Command 调用命令
iex Invoke-Expression 调用表达式
ihy Invoke-History 调用历史命令
ii Invoke-Item 调用项目
ipal Import-Alias 导入别名
ipcsv Import-Csv 导入 CSV
ipmo Import-Module 导入模块
irm Invoke-RestMethod 调用 REST 方法
iwr Invoke-WebRequest 调用 Web 请求
kill Stop-Process 停止进程
ls Get-ChildItem 获取子项目
man help 获取帮助
md mkdir 创建目录
measure Measure-Object 测量对象
mi Move-Item 移动项目
mount New-PSDrive 创建新驱动器
move Move-Item 移动项目
mp Move-ItemProperty 移动项目属性
mv Move-Item 移动项目
nal New-Alias 创建新别名
ndr New-PSDrive 创建新驱动器
ni New-Item 创建新项目
nmo New-Module 创建新模块
nsn New-PSSession 创建新 PSSession
nv New-Variable 创建新变量
ogv Out-GridView 输出到网格视图
oh Out-Host 输出到主机
popd Pop-Location 弹出位置
ps Get-Process 获取进程
pushd Push-Location 推送位置
pwd Get-Location 获取当前位置
r Invoke-History 调用历史命令
rbp Remove-PSBreakpoint 删除断点
rcjb Receive-Job 接收作业
rcsn Receive-PSSession 接收 PSSession
rd Remove-Item 删除项目
rdr Remove-PSDrive 删除驱动器
ren Rename-Item 重命名项目
ri Remove-Item 删除项目
rjb Remove-Job 删除作业
rm, rmdir Remove-Item 删除项目
rmo Remove-Module 删除模块
rni Rename-Item 重命名项目
rnp Rename-ItemProperty 重命名项目属性
rp Remove-ItemProperty 删除项目属性
rsn Remove-PSSession 删除 PSSession
rv Remove-Variable 删除变量
rvpa Resolve-Path 解析路径
sajb Start-Job 开始作业
sal Set-Alias 设置别名
saps Start-Process 开始进程
sasv Start-Service 开始服务
sbp Set-PSBreakpoint 设置断点
scb Set-Clipboard 设置剪贴板内容
select Select-Object 选择对象
set Set-Variable 设置变量
shcm Show-Command 显示命令
si Set-Item 设置项目
sl Set-Location 设置位置
sleep Start-Sleep 开始休眠
sls Select-String 选择字符串
sort Sort-Object 排序对象
sp Set-ItemProperty 设置项目属性
spjb Stop-Job 停止作业
spps Stop-Process 停止进程
spsv Stop-Service 停止服务
start Start-Process 开始进程
stz Set-TimeZone 设置时区
sv Set-Variable 设置变量
tee Tee-Object 分叉对象
type Get-Content 获取内容
where Where-Object 过滤对象
wjb Wait-Job 等待作业
write Write-Output 输出内容

三、cmdlet分类介绍

如果你想了解一个命令的说明和参数,可以使用Get-Help 命令名称 的格式获取,Get-Help的别名是man,例如你要获取Get-Help这个命令的帮助文档,可以使用:

man man

帮助文档是英文的,如果你有困难,可以去文章开头的微软中国官网搜索该命令,有中文的详细解释。

inserte la descripción de la imagen aquí


3.1 基础命令

1. Get-Command

Get-Command 是一个非常有用的 cmdlet,它可以列出所有可用的 cmdlet、函数、脚本和别名。例如,要查找与进程相关的所有命令,可以使用:

Get-Command *process*

2. Get-Help

Get-Help cmdlet 为用户提供了关于 cmdlet 和函数的详细信息。例如,要获取 Get-Process cmdlet 的帮助信息,可以使用:

Get-Help Get-Process

此外,-Examples-Detailed-Full 参数可以提供更多的信息。

3. Set-Variable

Set-Variable cmdlet 允许用户创建或修改一个变量。例如,要创建一个名为 “myVar” 的变量并为其赋值 “Hello, PowerShell!”,可以使用:

Set-Variable -Name myVar -Value "Hello, PowerShell!"

4. Get-Variable

Set-Variable 相对应,Get-Variable cmdlet 可以获取一个或多个变量的值。例如,要获取 “myVar” 的值,可以使用:

Get-Variable myVar

5. Remove-Variable

Remove-Variable cmdlet 允许用户删除一个或多个变量。例如,要删除 “myVar” 变量,可以使用:

Remove-Variable myVar

6. Clear-Variable

Clear-Variable cmdlet 用于清除变量的值,但不删除变量本身。例如,要清除 “myVar” 变量的值,可以使用:

Clear-Variable myVar

3.2 管理命令

1. Get-Process

Get-Process cmdlet 允许用户获取当前运行的进程信息。

Get-Process

这将列出所有当前运行的进程。你还可以通过指定进程名称来获取特定的进程信息,例如:

Get-Process -Name notepad

2. Stop-Process

Stop-Process cmdlet 用于终止一个或多个进程。例如,要终止名为 “notepad” 的进程,可以使用:

Stop-Process -Name notepad

3. Restart-Service

Restart-Service cmdlet 允许用户重新启动一个或多个服务。例如,要重新启动 “wuauserv” 服务(Windows Update 服务),可以使用:

Restart-Service -Name wuauserv

4. Get-Service

Get-Service cmdlet 提供了关于系统服务的信息。它可以列出所有服务或特定服务的状态。

Get-Service

要获取特定服务的信息,例如 “wuauserv”,可以使用:

Get-Service -Name wuauserv

5. Start-Service 和 Stop-Service

这两个 cmdlet 分别用于启动和停止服务。例如,要停止 “wuauserv” 服务,可以使用:

Stop-Service -Name wuauserv

要启动该服务,可以使用:

Start-Service -Name wuauserv

6. Get-EventLog

Get-EventLog cmdlet 允许用户读取和查询事件日志。例如,要获取系统日志中的最近 10 条事件,可以使用:

Get-EventLog -LogName System -Newest 10

3.3 实用工具命令

PowerShell 的实用工具命令提供了一系列功能,使用户能够进行文本和数据处理、文件操作、数据转换等任务。这些命令非常适合日常的数据处理和分析任务。以下是一些常用的实用工具命令及其功能介绍:

1. Sort-Object

Sort-Object cmdlet 用于对对象进行排序。例如,要按名称对进程进行排序,可以使用:

Get-Process | Sort-Object -Property ProcessName

2. Measure-Object

Measure-Object cmdlet 用于计算对象的数量、平均值、总和等。例如,要计算文本文件中的行数,可以使用:

Get-Content -Path "C:\path\to\file.txt" | Measure-Object -Line

3. ConvertTo-Json 和 ConvertFrom-Json

这两个 cmdlet 用于将对象转换为 JSON 格式,或从 JSON 格式转换为对象。例如,要将进程列表转换为 JSON 格式,可以使用:

Get-Process | ConvertTo-Json

反之,要从 JSON 格式转换为 PowerShell 对象,可以使用:

$jsonData | ConvertFrom-Json

4. Select-Object

Select-Object cmdlet 允许用户选择对象的特定属性。例如,要仅选择进程的名称和 ID,可以使用:

Get-Process | Select-Object -Property ProcessName, Id

5. Where-Object

Where-Object cmdlet 用于过滤对象。例如,要选择使用内存超过 100 MB 的进程,可以使用:

Get-Process | Where-Object {
    
    $_.WorkingSet64 -gt 100MB}

6. Out-File

Out-File cmdlet 用于将输出重定向到文件。例如,要将进程列表保存到文件中,可以使用:

Get-Process | Out-File -Path "C:\path\to\file.txt"

7. Compare-Object

Compare-Object cmdlet 用于比较两个对象集合的差异。例如,要比较两个文本文件的内容,可以使用:

Compare-Object $(Get-Content -Path "C:\path\to\file1.txt") $(Get-Content -Path "C:\path\to\file2.txt")

3.4 提供程序命令

PowerShell 提供程序是一种特殊的适配器,使得各种数据存储(如文件系统、注册表和证书存储)可以像文件系统一样被访问。这意味着你可以使用相同的命令(如 Get-ItemSet-Location 等)来操作这些不同的数据源。以下是与提供程序相关的一些常用命令及其功能介绍:

1. Get-PSProvider

Get-PSProvider cmdlet 显示所有已加载的 PowerShell 提供程序。执行此命令将列出如 FileSystemRegistryCertificate 等提供程序。

Get-PSProvider

2. Get-PSDrive

Get-PSDrive cmdlet 列出所有当前会话中的驱动器,包括由提供程序支持的驱动器。例如,除了常规的文件系统驱动器(如 C:、D:)之外,你还可能看到注册表驱动器(如 HKLM、HKCU)。

Get-PSDrive

inserte la descripción de la imagen aquí

3. New-PSDrive

New-PSDrive cmdlet 允许你创建一个新的 PowerShell 驱动器。例如,你可以创建一个指向特定注册表路径的新驱动器:

New-PSDrive -Name HKMyCustom -PSProvider Registry -Root HKEY_CURRENT_USER\Software\MyCustomPath

4. Remove-PSDrive

Remove-PSDrive cmdlet 用于删除之前使用 New-PSDrive 创建的驱动器。

Remove-PSDrive -Name HKMyCustom

5. Set-Location 和 Get-Location

这两个 cmdlet 用于导航到不同的 PowerShell 驱动器和路径。Set-Location(或其别名 cd)用于更改当前位置,而 Get-Location(或其别名 pwd)用于获取当前位置。

例如,要导航到之前创建的注册表驱动器,可以使用:

Set-Location -Path HKMyCustom:

然后,使用 Get-Location 可以确认你当前的位置。

6. Get-Item 和 Set-Item

这两个 cmdlet 用于获取和设置提供程序位置的项。例如,要获取注册表键的值,可以使用:

Get-Item -Path HKMyCustom:\SomeKeyName

要设置该键的值,可以使用:

Set-Item -Path HKMyCustom:\SomeKeyName -Value "NewValue"

3.5 模块和包命令

在 PowerShell 中,模块是一个包含多个函数、cmdlet、提供程序和变量的包。这些模块可以被导入到 PowerShell 会话中,以增强其功能。包则是通过包管理器(如 PowerShellGet)分发的模块或脚本。以下是与模块和包相关的一些常用命令及其功能介绍:

1. Import-Module

Import-Module cmdlet 允许你导入一个模块,使其在当前会话中可用。例如,要导入名为 “MyModule” 的模块,可以使用:

Import-Module -Name MyModule

2. Remove-Module

Remove-Module cmdlet 用于从当前会话中卸载模块。例如,要卸载 “MyModule”,可以使用:

Remove-Module -Name MyModule

3. Get-Module

Get-Module cmdlet 显示已导入或可用的模块。使用 -ListAvailable 参数可以列出所有可用的模块:

Get-Module -ListAvailable

4. Install-Module

Install-Module cmdlet 允许你从 PowerShell 库或其他存储库安装模块。例如,要安装 “PSReadline” 模块,可以使用:

Install-Module -Name PSReadline

5. Uninstall-Module

Uninstall-Module cmdlet 用于从系统中卸载模块。例如,要卸载 “PSReadline” 模块,可以使用:

Uninstall-Module -Name PSReadline

6. Find-Module

Find-Module cmdlet 允许你在 PowerShell 库中搜索模块。例如,要查找与 “Azure” 相关的所有模块,可以使用:

Find-Module -Name *Azure*

7. Save-Module

Save-Module cmdlet 允许你下载模块但不安装它。这对于在没有互联网连接的环境中手动安装模块很有用。例如,要下载 “PSReadline” 模块,可以使用:

Save-Module -Name PSReadline -Path C:\path\to\directory

3.6 调试命令

在开发和运行 PowerShell 脚本时,可能会遇到错误或异常。为了帮助用户识别和解决这些问题,PowerShell 提供了一组调试命令。这些命令允许用户设置断点、检查变量的值、跟踪执行流程等,从而更容易地找到和修复问题。以下是与调试相关的一些常用命令及其功能介绍:

1. Set-PSBreakpoint (sbp)

Set-PSBreakpoint cmdlet 允许用户在脚本、行或命令上设置断点。当执行到断点时,脚本的执行将暂停,允许用户检查当前的状态。

例如,要在 “myscript.ps1” 脚本的第 10 行设置断点,可以使用:

Set-PSBreakpoint -Script myscript.ps1 -Line 10

2. Get-PSBreakpoint

Get-PSBreakpoint cmdlet 显示当前设置的所有断点。

Get-PSBreakpoint

3. Remove-PSBreakpoint (rbp)

Remove-PSBreakpoint cmdlet 允许用户删除一个或多个断点。例如,要删除 ID 为 1 的断点,可以使用:

Remove-PSBreakpoint -ID 1

4. Get-PSCallStack

Get-PSCallStack cmdlet 显示当前的调用堆栈。这对于理解脚本的执行流程和确定当前执行的位置非常有用。

Get-PSCallStack

5. Trace-Command

Trace-Command cmdlet 允许用户跟踪特定命令的执行,以获取详细的调试信息。例如,要跟踪 “Get-ChildItem” 命令的执行,可以使用:

Trace-Command -Name Metadata -Expression {
    
     Get-ChildItem } -PSHost

6. Enter-PSHostProcess 和 Exit-PSHostProcess

这两个 cmdlet 允许用户进入和退出另一个 PowerShell 进程的会话,这对于调试运行中的脚本非常有用。

例如,要进入进程 ID 为 1234 的 PowerShell 进程,可以使用:

Enter-PSHostProcess -Id 1234

退出该进程的会话后,可以使用:

Exit-PSHostProcess

3.7 远程命令

PowerShell 的远程功能允许用户从一个计算机连接到另一个计算机,并在远程计算机上执行命令和脚本。这对于管理大型网络、自动化跨多台机器的任务或简单地从一个位置访问另一个位置的资源非常有用。以下是与远程相关的一些常用命令及其功能介绍:

1. Enter-PSSession

Enter-PSSession cmdlet 允许用户启动一个交互式会话到远程计算机。例如,要连接到名为 “RemoteServer” 的远程计算机,可以使用:

Enter-PSSession -ComputerName RemoteServer

在此会话中,你可以执行命令就像在远程计算机的本地会话中一样。

2. Exit-PSSession

当你完成远程会话并想返回到本地计算机时,可以使用 Exit-PSSession cmdlet。

Exit-PSSession

3. Invoke-Command

Invoke-Command cmdlet 允许用户在一个或多个远程计算机上执行命令或脚本。例如,要在 “RemoteServer” 上执行 “Get-Process” 命令,可以使用:

Invoke-Command -ComputerName RemoteServer -ScriptBlock {
    
     Get-Process }

4. New-PSSession

New-PSSession cmdlet 允许用户创建一个或多个持久的远程会话。这些会话可以用于多次远程命令调用,而不必每次都重新建立连接。

$session = New-PSSession -ComputerName RemoteServer

5. Remove-PSSession

Remove-PSSession cmdlet 用于关闭并删除之前使用 New-PSSession 创建的远程会话。

Remove-PSSession -Session $session

6. Export-PSSession

Export-PSSession cmdlet 允许用户从远程会话导出命令、函数、别名和其他信息,并将它们保存为一个模块。这对于在本地计算机上使用远程计算机的功能非常有用。

Export-PSSession -Session $session -OutputModule RemoteFunctions

7. Enable-PSRemoting 和 Disable-PSRemoting

这两个 cmdlet 用于启用或禁用计算机上的 PowerShell 远程功能。

要启用远程功能,可以使用:

Enable-PSRemoting

要禁用远程功能,可以使用:

Disable-PSRemoting

四、特殊操作符

PowerShell 提供了一系列特殊操作符,用于执行各种任务,如比较、模式匹配、数组操作等。以下是 PowerShell 中可用的特殊操作符及其详细介绍:

1. 算术操作符

  • -:减法
  • +:加法
  • *:乘法
  • /:除法
  • %:取余

2. 赋值操作符

  • =:赋值
  • +=:增加并赋值
  • -=:减少并赋值
  • *=:乘以并赋值
  • /=:除以并赋值

3. 比较操作符

  • -eq:等于
  • -ne:不等于
  • -gt:大于
  • -lt:小于
  • -ge:大于或等于
  • -le:小于或等于
  • -like:使用通配符进行字符串比较
  • -notlike:不使用通配符进行字符串比较
  • -match:使用正则表达式进行匹配
  • -notmatch:不使用正则表达式进行匹配

4. 逻辑操作符

  • -and:逻辑与
  • -or:逻辑或
  • -not:逻辑非
  • !:逻辑非的简写形式

5. 位操作符

  • -band:位与
  • -bor:位或
  • -bxor:位异或
  • -bnot:位非
  • -shl:左移
  • -shr:右移

6. 重定向操作符

  • >:将输出重定向到文件,覆盖文件内容
  • >>:将输出追加到文件
  • 2>:将错误输出重定向到文件
  • 2>&1:将错误输出和正常输出合并

7. 特殊操作符

  • -contains:检查数组是否包含特定值
  • -notcontains:检查数组是否不包含特定值
  • -in:检查值是否在数组中
  • -notin:检查值是否不在数组中
  • -replace:使用正则表达式替换字符串
  • -split:使用正则表达式分割字符串
  • -join:连接数组中的元素为一个字符串

8. 类型操作符

  • -is:检查对象是否为特定类型
  • -isnot:检查对象是否不为特定类型
  • -as:尝试将对象转换为特定类型

五、运行Windows命令行工具

5.1 常用命令行工具

PowerShell 不仅支持其自己的 cmdlets,还支持传统的 Windows 命令行工具。这意味着你可以在 PowerShell 会话中直接运行这些工具,而无需切换到命令提示符(CMD)。以下是一些常用的 Windows 命令行工具及其简要描述:

1. ipconfig

ipconfig 是一个用于查看和管理 Windows IP 配置的工具。

  • 基本用法ipconfig 显示计算机的所有网络接口的 IP 地址、子网掩码和默认网关。
  • 参数
    • /all:显示所有网络接口的详细信息。
    • /release:释放指定适配器的 IP 地址。
    • /renew:更新指定适配器的 IP 地址。
    • /flushdns:清除 DNS 解析器缓存。
    • /displaydns:显示 DNS 解析器缓存的内容。
    • /registerdns:刷新所有 DHCP 租约并重新注册 DNS 名称。

2. netstat

netstat 用于显示活动的网络连接、端口和网络统计信息。

  • 基本用法netstat 显示活动的网络连接。
  • 参数
    • -a:显示所有活动的网络连接和监听的端口。
    • -b:显示在创建每个连接或监听端口时涉及的可执行文件。
    • -n:以数字形式显示地址和端口号。
    • -o:显示与每个连接关联的所有者的进程 ID。

3. ping

ping 工具用于测试网络连接的可达性。

  • 基本用法ping [目标主机名或 IP] 向指定的主机或 IP 发送 ICMP 请求。
  • 参数
    • -t:持续发送 ping 请求,直到用户中断。
    • -a:解析主机名。
    • -n [次数]:发送指定次数的 echo 请求。
    • -l [大小]:发送指定大小的数据。

4. tracert

tracert 是一个用于诊断路由路径的工具。

  • 基本用法tracert [目标主机名或 IP] 显示数据包从源计算机到指定目标的路由路径。
  • 参数
    • -d:不解析地址。
    • -h [最大跃点数]:指定最大跃点数。
    • -j [主机列表]:沿途经过的主机列表。

5. nslookup

nslookup 是一个用于查询 DNS 名称和 IP 地址的工具。

  • 基本用法nslookup [主机名] 查询指定主机名的 IP 地址。
  • 参数
    • -type:查询的资源记录类型,如 A、MX、PTR 等。
    • -debug:在响应中显示详细的开发信息。

6. sfc

sfc 是系统文件检查器,用于扫描和修复 Windows 系统文件。

  • 基本用法sfc /scannow 扫描并尝试修复任何损坏的系统文件。
  • 参数
    • /verifyonly:仅扫描并验证系统文件的完整性。
    • /offbootdir:指定启动目录。
    • /offwindir:指定 Windows 目录。

7. chkdsk

chkdsk 是一个用于检查和修复磁盘错误的工具。

  • 基本用法chkdsk [驱动器:] 检查指定的驱动器。
  • 参数
    • /f:修复磁盘上的错误。
    • /r:查找坏扇区并恢复可读信息。
    • /x:强制卷在检查前先卸载。

8. systeminfo

systeminfo 工具用于显示详细的系统信息。

  • 基本用法systeminfo 显示操作系统、硬件和网络配置的详细信息。
  • 参数
    • /s [计算机名]:指定要查看的远程系统。
    • /u [用户名]:指定用户名进行身份验证。

9. gpupdate

gpupdate 是一个用于手动更新组策略的工具。

  • 基本用法gpupdate 更新组策略。
  • 参数
    • /force:强制重新应用所有设置。
    • /logoff:如果需要,完成后注销用户。

10. tasklist

tasklist 工具用于显示当前运行的进程列表。

  • 基本用法tasklist 显示所有当前运行的进程及其详细信息。
  • 参数
    • /s [计算机名]:指定要查看的远程系统。
    • /u [用户名]:指定用户名进行身份验证。
    • /fi [过滤条件]:按照指定的条件显示任务列表。

这些命令行工具在日常的系统管理和故障排查中都非常有用。了解它们的参数和用法可以帮助你更有效地使用这些工具。

5.2 对应的cmdlet

Windows Tool PowerShell Cmdlet
ipconfig Get-NetIPAddress
netstat Get-NetTCPConnection
ping Test-Connection
tracert Test-NetConnection -TraceRoute
nslookup Resolve-DnsName
sfc Repair-WindowsImage
chkdsk Repair-Volume
systeminfo Get-ComputerInfo
gpupdate Invoke-GPUpdate
tasklist Get-Process

六、运行用户程序

除此,之外,我们自己安装的一些命令行应用也可以在Powershell中运行。

在Powershell中使用下列工具时,请先安装,并且添加到环境变量。

在Windows下,很多功能并不需要在终端中完成,使用图形化界面可能更省事,本文只是做个介绍


6.1 vim(nvim)

nvim是vim的一个分支,更加友好,我之前的文章专门介绍过。

这里去github下载Windows版本的nvim使用。

和在Linux终端中的使用方式一样。


示例:

inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí

6.2 gcc / gdb

我是使用MinGW(Minimalist GNU for Windows)安装的gcc和gdb。

使用示例: 一个tcp服务端程序。

编译和运行
inserte la descripción de la imagen aquí
调试
inserte la descripción de la imagen aquí


Escribe te amo para siempre al final del poema ~

Supongo que te gusta

Origin blog.csdn.net/weixin_43764974/article/details/132255181
Recomendado
Clasificación