系统运维
Windows 运维命令大全
PowerShell 与 CMD 的系统信息、进程服务、网络、防火墙、账户权限、磁盘和故障恢复命令。
先看安全提示
涉及 diskpart、format、bcdedit、注册表删除、防火墙放行、ACL 修改和关机重启的命令必须先确认目标与备份。
显示 174 / 174 条
系统信息
12 条先记录系统版本、补丁和硬件信息,便于比对与回滚。
| 命令 / 语法 | 说明 | 示例 | 平台 | 来源 |
|---|---|---|---|---|
systeminfo |
输出 Windows 版本、补丁、内存、网卡等摘要。 | systeminfo |
Microsoft Learn · systeminfo | |
ver |
只输出当前 Windows 版本号,适合快速确认系统代际。 | ver |
Microsoft Learn · ver | |
driverquerydriverquery [/v] [/fo <format>] |
列出已安装驱动、显示名称、类型和运行状态。 | driverquery /v /fo table |
Microsoft Learn · driverquery | |
chcpchcp [code-page] |
查看或切换控制台代码页;65001 表示 UTF-8。 | chcp 65001 |
Microsoft Learn · chcp | |
Get-ComputerInfo |
PowerShell 的系统与硬件信息对象,可筛选字段。 | Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion, CsTotalPhysicalMemory |
Microsoft Learn · Get-ComputerInfo | |
Get-CimInstance Win32_OperatingSystem |
读取操作系统版本、安装时间和最后启动时间。 | Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Version, LastBootUpTime |
Microsoft Learn · Get-CimInstance | |
Get-ProcessGet-Process [-Name <name>] |
列出进程及 CPU、内存占用,可按名称过滤。 | Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 |
Microsoft Learn · Get-Process | |
Get-HotFixGet-HotFix [-Id <KB>] |
列出已安装的系统补丁、安装日期和安装来源。 | Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 10 |
Microsoft Learn · Get-HotFix | |
hostname |
输出本机计算机名,适合脚本中快速读取。 | hostname |
Microsoft Learn · hostname | |
Win32_BIOSGet-CimInstance Win32_BIOS |
读取 BIOS 厂商、版本、序列号和发布日期。 | Get-CimInstance Win32_BIOS | Select-Object Manufacturer, SMBIOSBIOSVersion, SerialNumber |
Microsoft Learn · Get-CimInstance | |
Win32_ProcessorGet-CimInstance Win32_Processor |
查看 CPU 型号、核心数、逻辑处理器数和当前时钟。 | Get-CimInstance Win32_Processor | Select-Object Name, NumberOfCores, NumberOfLogicalProcessors |
Microsoft Learn · Get-CimInstance | |
Win32_LogicalDiskGet-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
读取本地固定磁盘的容量、剩余空间和文件系统。 | Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" | Select-Object DeviceID, Size, FreeSpace |
Microsoft Learn · Get-CimInstance |
进程与服务
25 条停止服务或进程前先确认影响范围;生产机优先使用服务管理器或变更流程。
| 命令 / 语法 | 说明 | 示例 | 平台 | 来源 |
|---|---|---|---|---|
tasklisttasklist [/FI <filter>] |
CMD 下列出进程;/FI 可按 PID、映像名筛选。 | tasklist /FI "IMAGENAME eq chrome.exe" |
Microsoft Learn · tasklist | |
tasklist /svctasklist /svc [/FI <filter>] |
列出进程及其承载的 Windows 服务,便于定位服务宿主。 | tasklist /svc /FI "IMAGENAME eq svchost.exe" |
Microsoft Learn · tasklist | |
Stop-ProcessStop-Process -Name <name> [-Force]危险强制结束进程可能造成未保存数据丢失。
|
按名称或 PID 停止进程;-Force 会跳过确认。 | Stop-Process -Name notepad -Force |
Microsoft Learn · Stop-Process | |
taskkilltaskkill /PID <pid> [/F] [/T]危险/F 强制结束,/T 会连带结束子进程。
|
按 PID 结束进程;/T 同时结束子进程。 | taskkill /PID 1234 /F /T |
Microsoft Learn · taskkill | |
Get-ServiceGet-Service [-Name <name>] |
查看服务状态、启动类型和依赖关系。 | Get-Service | Where-Object Status -eq 'Running' |
Microsoft Learn · Get-Service | |
Restart-ServiceRestart-Service -Name <name>危险重启服务会短暂中断依赖它的功能。
|
重启指定服务;可能需要管理员权限。 | Restart-Service -Name Spooler |
Microsoft Learn · Restart-Service | |
sc querysc query <service> |
查询服务状态;sc 与 PowerShell 的 Get-Service 不同。 | sc query Spooler |
Microsoft Learn · sc | |
sc startsc start <service> |
启动服务;服务名不是显示名,需先用 sc query 确认。 | sc start Spooler |
Microsoft Learn · sc | |
sc stopsc stop <service>危险停止关键服务会中断业务,生产机先确认依赖和回滚方式。
|
停止服务;依赖该服务的功能会中断。 | sc stop Spooler |
Microsoft Learn · sc | |
sc configsc config <service> start= <auto|demand|disabled>危险禁用关键服务可能导致系统功能或应用无法启动。
|
修改服务启动类型;等号后必须有空格。 | sc config Spooler start= demand |
Microsoft Learn · sc | |
net startnet start [service] |
列出运行中的服务,或启动指定服务。 | net start Spooler |
SS64 · net start | |
net stopnet stop <service>危险停止服务会影响依赖组件;/y 会跳过确认。
|
停止指定服务,并提示仍依赖它的服务。 | net stop Spooler |
SS64 · net stop | |
Get-WinEventGet-WinEvent -LogName <log> [-MaxEvents <n>] |
读取事件日志,适合排查启动、崩溃和策略问题。 | Get-WinEvent -LogName System -MaxEvents 20 |
Microsoft Learn · Get-WinEvent | |
Get-ScheduledTaskGet-ScheduledTask [-TaskName <name>] |
查看计划任务及其状态。 | Get-ScheduledTask | Where-Object State -eq 'Ready' |
Microsoft Learn · Get-ScheduledTask | |
Register-ScheduledTaskRegister-ScheduledTask -TaskName <name> -Action <action> -Trigger <trigger> |
注册计划任务;通常先构造 Action、Trigger 和 Principal。 | $a=New-ScheduledTaskAction -Execute 'notepad.exe'; Register-ScheduledTask -TaskName 'OpenNotepad' -Action $a |
Microsoft Learn · Register-ScheduledTask | |
Start-ServiceStart-Service -Name <name> |
启动已停止的服务;依赖服务未就绪时可能失败。 | Start-Service -Name Spooler |
Microsoft Learn · Start-Service | |
Stop-ServiceStop-Service -Name <name> [-Force]危险停止关键服务会中断业务;-Force 还会影响依赖服务。
|
停止服务;-Force 会同时停止依赖该服务的服务。 | Stop-Service -Name Spooler |
Microsoft Learn · Stop-Service | |
Set-ServiceSet-Service -Name <name> -StartupType <type>危险禁用关键服务可能导致系统功能或应用无法启动。
|
修改服务启动类型,如 Automatic、Manual、Disabled。 | Set-Service -Name Spooler -StartupType Manual |
Microsoft Learn · Set-Service | |
schtasksschtasks /query [/tn <name>] [/fo LIST] |
CMD 查询计划任务;/run 立即运行,/end 结束任务。 | schtasks /query /tn "\Microsoft\Windows\Defrag\ScheduledDefrag" /v /fo LIST |
Microsoft Learn · schtasks | |
schtasks /createschtasks /create /tn <name> /tr <command> /sc <schedule>危险任务会按配置自动执行;确认命令路径、运行账户和触发时间。
|
创建计划任务;/sc 支持 DAILY、WEEKLY、ONLOGON 等。 | schtasks /create /tn "DailyBackup" /tr "D:\scripts\backup.cmd" /sc daily /st 02:00 |
Microsoft Learn · schtasks | |
schtasks /runschtasks /run /tn <name> |
立即运行已注册的计划任务。 | schtasks /run /tn "DailyBackup" |
Microsoft Learn · schtasks | |
schtasks /deleteschtasks /delete /tn <name> [/f]危险删除后任务不会自动恢复;先导出或记录任务配置。
|
删除计划任务;/f 跳过确认。 | schtasks /delete /tn "DailyBackup" /f |
Microsoft Learn · schtasks | |
startstart "" <program> [args] |
在新窗口启动程序、文件或 URL;空标题可避免路径被当作窗口标题。 | start "" notepad.exe D:\logs\app.log |
Microsoft Learn · start | |
timeouttimeout /t <seconds> [/nobreak] |
在批处理中等待指定秒数;/nobreak 忽略按键。 | timeout /t 10 /nobreak |
Microsoft Learn · timeout | |
Start-ScheduledTaskStart-ScheduledTask -TaskName <name> |
立即触发计划任务,适合验证任务动作和权限。 | Start-ScheduledTask -TaskName 'OpenNotepad' |
Microsoft Learn · Start-ScheduledTask |
网络
31 条先看地址与 DNS,再看端口和路由;不要用“重置网络”代替定位。确需重置时先记录 ipconfig /all、route print 和 Wi-Fi 配置,完成后重启。
| 命令 / 语法 | 说明 | 示例 | 平台 | 来源 |
|---|---|---|---|---|
ipconfig /all |
查看所有适配器的 IP、网关、DNS、DHCP 和 MAC 地址。 | ipconfig /all |
Microsoft Learn · ipconfig | |
ipconfig /releaseipconfig [/release [adapter]]危险会暂时断开网络,远程操作时可能失去连接。
|
释放 DHCP 地址;执行后该适配器可能暂时断网。 | ipconfig /release |
Microsoft Learn · ipconfig | |
ipconfig /renewipconfig [/renew [adapter]] |
向 DHCP 服务器重新申请地址。 | ipconfig /renew |
Microsoft Learn · ipconfig | |
ipconfig /displaydns |
显示本机 DNS 缓存中的记录和 TTL。 | ipconfig /displaydns |
Microsoft Learn · ipconfig | |
ipconfig /flushdns |
清空本机 DNS 解析缓存。 | ipconfig /flushdns |
Microsoft Learn · ipconfig | |
netstat -ano |
查看活动连接、监听端口和对应 PID。 | netstat -ano | findstr :443 |
Microsoft Learn · netstat | |
Test-NetConnectionTest-NetConnection <host> -Port <port> |
测试目标主机的指定 TCP 端口是否可达。 | Test-NetConnection zuhejian.com -Port 443 |
Microsoft Learn · Test-NetConnection | |
Get-NetTCPConnectionGet-NetTCPConnection [-State Listen] |
查看 TCP 连接和监听状态,可关联 OwningProcess。 | Get-NetTCPConnection -State Listen | Sort-Object LocalPort |
Microsoft Learn · Get-NetTCPConnection | |
Get-NetIPConfiguration |
查看接口、IPv4/IPv6 地址、网关和 DNS。 | Get-NetIPConfiguration |
Microsoft Learn · Get-NetIPConfiguration | |
nslookupnslookup <domain> [dns-server] |
查询域名解析,可指定 DNS 服务器对比结果。 | nslookup zuhejian.com 1.1.1.1 |
Microsoft Learn · nslookup | |
Test-ConnectionTest-Connection <host> -Count <n> |
PowerShell 的 ping 替代品,返回结构化对象而不是纯文本。 | Test-Connection zuhejian.com -Count 4 |
Microsoft Learn · Test-Connection | |
Resolve-DnsNameResolve-DnsName <domain> [-Type <type>] |
查询 A、AAAA、CNAME、MX、TXT 等 DNS 记录。 | Resolve-DnsName zuhejian.com -Type A |
Microsoft Learn · Resolve-DnsName | |
Clear-DnsClientCache |
清空 Windows DNS 客户端缓存,等价于 ipconfig /flushdns。 | Clear-DnsClientCache |
Microsoft Learn · Clear-DnsClientCache | |
Get-DnsClientServerAddressGet-DnsClientServerAddress -AddressFamily IPv4 |
按接口查看当前使用的 DNS 服务器地址。 | Get-DnsClientServerAddress -AddressFamily IPv4 |
Microsoft Learn · Get-DnsClientServerAddress | |
Get-NetAdapterGet-NetAdapter [-Physical] |
查看网卡名称、状态、速率和 MAC 地址。 | Get-NetAdapter | Select-Object Name, Status, LinkSpeed, MacAddress |
Microsoft Learn · Get-NetAdapter | |
route print |
打印 IPv4/IPv6 路由表,排查默认网关和多网卡选路。 | route print |
Microsoft Learn · route | |
route addroute add <network> mask <mask> <gateway>危险错误路由会导致目标网段不可达;先 route print 确认现有规则。
|
添加临时静态路由;重启后默认失效,持久化需加 -p。 | route add 10.20.0.0 mask 255.255.0.0 192.168.1.1 |
Microsoft Learn · route | |
arp -aarp -a [interface] |
查看本机 ARP 缓存,确认 IP 与 MAC 的对应关系。 | arp -a |
Microsoft Learn · arp | |
getmac /vgetmac /v [/fo <format>] |
列出网卡 MAC 地址、传输名称和连接状态。 | getmac /v /fo table |
Microsoft Learn · getmac | |
pingping <host> [-n <count>] [-t] |
测试 ICMP 连通性和延迟;-t 持续发送,Ctrl+C 停止。 | ping zuhejian.com -n 4 |
Microsoft Learn · ping | |
tracerttracert [-d] <host> |
逐跳显示到目标的路由;-d 不解析主机名。 | tracert -d zuhejian.com |
Microsoft Learn · tracert | |
pathpingpathping <host> |
结合路由跟踪和丢包统计,适合定位中间节点丢包。 | pathping zuhejian.com |
Microsoft Learn · pathping | |
net usenet use [drive:] \\<host>\<share> [/user:<user>]危险凭据会进入当前会话;不要在共享机器保存高权限凭据。
|
映射网络共享或查看现有连接;/delete 断开映射。 | net use Z: \\server01\share /user:DOMAIN\user |
SS64 · net use | |
net sharenet share [name=<path>] [/delete]危险创建共享会扩大访问面;删除共享会中断现有客户端。
|
查看、创建或删除 SMB 共享。 | net share |
SS64 · net share | |
net viewnet view [\\<host>] |
查看域或指定主机上可见的共享资源。 | net view \\server01 |
SS64 · net view | |
curlcurl -I <url> |
Windows 10/11 自带 curl;-I 只取响应头,适合检查状态码和缓存。 | curl -I https://zuhejian.com/ |
curl · 命令行手册 | |
netsh wlan show profilesnetsh wlan show profiles [name=<profile>] key=clear危险key=clear 会在终端暴露 Wi-Fi 密码,避免在共享屏幕时执行。
|
查看已保存的 Wi-Fi 配置;key=clear 会显示明文密码。 | netsh wlan show profiles |
Microsoft Learn · netsh | |
netsh winsock resetnetsh winsock reset [catalog]危险会移除第三方 LSP;重置后必须重启,VPN、代理或安全软件可能需要重新安装。
|
把 Winsock 目录重置为安装默认状态,修复 LSP 损坏导致的断网、代理或 VPN 异常。 | netsh winsock reset |
Microsoft Learn · netsh | |
netsh int ip resetnetsh int ip reset [log-file]危险会改写 TCP/IP 注册表配置;重置后必须重启,静态 IP、路由或代理设置需重新配置。
|
把 TCP/IP 协议栈重置为安装状态;可附带日志路径,等价于 netsh interface ip reset。 | netsh int ip reset C:\Windows\Temp\ip-reset.log |
Microsoft Learn · netsh | |
netsh int ipv4 resetnetsh int ipv4 reset [log-file]危险会重置 IPv4 配置并要求重启;执行前记录 ipconfig /all 和 route print。
|
只重置 IPv4 协议栈,适合 IPv4 地址、网关或路由异常且需要缩小影响范围时。 | netsh int ipv4 reset %TEMP%\ipv4-reset.log |
Microsoft Learn · netsh | |
netsh int ipv6 resetnetsh int ipv6 reset [log-file]危险会重置 IPv6 配置并要求重启;双栈环境先确认业务不依赖固定 IPv6 地址。
|
只重置 IPv6 协议栈,用于 IPv6 地址、邻居发现或隧道异常。 | netsh int ipv6 reset %TEMP%\ipv6-reset.log |
Microsoft Learn · netsh |
防火墙与远程管理
17 条修改防火墙或启用远程管理前,先保留控制台/带外访问,避免把自己锁在机器外。
| 命令 / 语法 | 说明 | 示例 | 平台 | 来源 |
|---|---|---|---|---|
Get-NetFirewallProfile |
查看域、专用和公用网络的防火墙开关及默认策略。 | Get-NetFirewallProfile | Select-Object Name, Enabled, DefaultInboundAction |
Microsoft Learn · Get-NetFirewallProfile | |
Get-NetFirewallRuleGet-NetFirewallRule -DisplayName <name> |
按显示名、方向或启用状态查询防火墙规则。 | Get-NetFirewallRule -DisplayName '*Remote Desktop*' | Select-Object DisplayName, Enabled, Direction |
Microsoft Learn · Get-NetFirewallRule | |
New-NetFirewallRuleNew-NetFirewallRule -DisplayName <name> -Direction Inbound -Protocol TCP -LocalPort <port> -Action Allow危险错误地放行入站端口会扩大攻击面;先确认端口、来源和配置文件。
|
创建入站或出站防火墙规则;默认会立即生效。 | New-NetFirewallRule -DisplayName 'Allow HTTPS 8443' -Direction Inbound -Protocol TCP -LocalPort 8443 -Action Allow |
Microsoft Learn · New-NetFirewallRule | |
netsh advfirewallnetsh advfirewall firewall show rule name=all |
CMD 查看防火墙规则和配置文件;也可启用或禁用规则。 | netsh advfirewall firewall show rule name=all |
Microsoft Learn · netsh | |
netsh advfirewall firewall add rulenetsh advfirewall firewall add rule name=<name> dir=in action=allow protocol=TCP localport=<port>危险错误放行会扩大攻击面;先确认端口、方向、协议和配置文件。
|
新增入站或出站规则;dir、action、protocol 必须成组确认。 | netsh advfirewall firewall add rule name="HTTPS 8443" dir=in action=allow protocol=TCP localport=8443 |
Microsoft Learn · netsh | |
netsh advfirewall set allprofiles state on |
启用域、专用、公用三个配置文件的防火墙。 | netsh advfirewall set allprofiles state on |
Microsoft Learn · netsh | |
netsh advfirewall exportnetsh advfirewall export <file.wfw> |
导出当前防火墙策略,便于变更前备份和回滚。 | netsh advfirewall export D:\backup\firewall.wfw |
Microsoft Learn · netsh | |
netsh advfirewall importnetsh advfirewall import <file.wfw>危险导入会覆盖现有策略,远程操作可能导致连接中断。
|
导入防火墙策略;会替换当前配置。 | netsh advfirewall import D:\backup\firewall.wfw |
Microsoft Learn · netsh | |
Enable-PSRemotingEnable-PSRemoting -Force危险会开放远程管理通道,生产环境需配合网络访问控制和凭据策略。
|
启用 WinRM 和 PowerShell 远程管理;会修改服务、防火墙和监听配置。 | Enable-PSRemoting -Force |
Microsoft Learn · Enable-PSRemoting | |
Enter-PSSessionEnter-PSSession -ComputerName <host> -Credential <user> |
建立交互式 PowerShell 远程会话;exit 退出。 | Enter-PSSession -ComputerName server01 -Credential admin |
Microsoft Learn · Enter-PSSession | |
Invoke-CommandInvoke-Command -ComputerName <host> -ScriptBlock { <command> } |
在多台主机上执行脚本块并返回结果,适合批量巡检。 | Invoke-Command -ComputerName server01,server02 -ScriptBlock { Get-Service Spooler } |
Microsoft Learn · Invoke-Command | |
winrm quickconfig危险会开放远程管理通道;生产环境需限制来源并配置凭据策略。
|
快速启用 WinRM 服务、监听器和防火墙例外。 | winrm quickconfig |
Microsoft Learn · WinRM 安装与配置 | |
winrswinrs -r:<host> <command> |
通过 WinRM 在远程主机执行单条命令。 | winrs -r:server01 ipconfig /all |
Microsoft Learn · winrs | |
mstscmstsc /v:<host> [/f] [/w:<width> /h:<height>] |
启动远程桌面连接;/v 指定目标,/f 全屏。 | mstsc /v:server01 /f |
Microsoft Learn · mstsc | |
query sessionquery session [user] [/server:<host>] |
查看本机或远程主机的登录会话、会话 ID 和状态。 | query session |
Microsoft Learn · query | |
logofflogoff <session-id> [/server:<host>]危险强制注销会关闭该会话中的程序并丢失未保存内容。
|
注销指定会话;未保存的数据会丢失。 | logoff 2 |
Microsoft Learn · logoff | |
Get-SmbShare |
查看本机 SMB 共享、路径和描述。 | Get-SmbShare | Select-Object Name, Path, Description |
Microsoft Learn · Get-SmbShare |
账户、权限与加密
13 条权限变更遵循最小权限原则;修改 ACL 或 BitLocker 前确认恢复密钥和回滚方式。
| 命令 / 语法 | 说明 | 示例 | 平台 | 来源 |
|---|---|---|---|---|
Get-LocalUser |
列出本机账户、启用状态和上次登录时间。 | Get-LocalUser | Select-Object Name, Enabled, LastLogon |
Microsoft Learn · Get-LocalUser | |
Get-LocalGroupMemberGet-LocalGroupMember -Group <group> |
查看本地组成员,快速确认管理员权限归属。 | Get-LocalGroupMember -Group Administrators |
Microsoft Learn · Get-LocalGroupMember | |
net usernet user [username] [password] [/add] [/domain] |
查看账户信息;带密码和 /add 时创建或修改账户。 | net user Administrator |
Microsoft Learn · net user | |
net accounts |
查看密码最短长度、有效期、锁定阈值等账户策略。 | net accounts |
SS64 · net accounts | |
net localgroup administratorsnet localgroup administrators [user] /add危险加入管理员组等于授予本机最高权限,必须确认账户和审批。
|
查看本地管理员组成员,或把用户加入管理员组。 | net localgroup administrators |
SS64 · net localgroup | |
runasrunas /user:<user> <program>危险会启动高权限进程;不要在不可信程序上使用管理员账户。
|
以其他用户身份启动程序,适合临时提权排查。 | runas /user:Administrator cmd.exe |
SS64 · runas | |
cmdkey /listcmdkey /list [target] |
列出当前用户保存的凭据目标;不会显示明文密码。 | cmdkey /list |
Microsoft Learn · cmdkey | |
whoami /priv |
查看当前令牌启用的特权,如备份、调试、关机。 | whoami /priv |
Microsoft Learn · whoami | |
cipher /ecipher /e <path>危险EFS 密钥丢失后数据无法恢复,先备份证书和私钥。
|
对文件或目录启用 EFS 加密;/d 解密,/status 查看状态。 | cipher /e D:\private |
Microsoft Learn · cipher | |
certutil -hashfilecertutil -hashfile <file> <SHA256> |
计算文件哈希,校验下载包或安装介质完整性。 | certutil -hashfile .\installer.exe SHA256 |
Microsoft Learn · certutil | |
icaclsicacls <path> [/grant <user>:<perm>] [/remove <user>]危险错误的 ACL 可能导致服务无法读取文件或用户获得过高权限。
|
查看或修改 NTFS ACL;先查看再变更,避免破坏继承权限。 | icacls .\site /grant "IIS_IUSRS:(OI)(CI)RX" |
Microsoft Learn · icacls | |
takeowntakeown /f <path> [/r] [/d Y]危险递归取得所有权会改变整个目录树的权限归属。
|
取得文件或目录所有权;/r 递归处理子项。 | takeown /f .\locked-file.txt |
Microsoft Learn · takeown | |
Get-BitLockerVolume |
查看卷的 BitLocker 状态、加密百分比和保护器类型。 | Get-BitLockerVolume | Select-Object MountPoint, VolumeStatus, EncryptionPercentage |
Microsoft Learn · Get-BitLockerVolume |
文件与磁盘
32 条磁盘操作先确认盘符和设备号;格式化会清除分区数据。
| 命令 / 语法 | 说明 | 示例 | 平台 | 来源 |
|---|---|---|---|---|
dir /adir [/a] [/s] [/b] [path] |
列出目录内容;/a 含隐藏项,/s 递归,/b 只输出名称。 | dir /a /s C:\Logs |
Microsoft Learn · dir | |
cd /dcd /d <path> |
切换当前目录,/d 允许同时切换盘符。 | cd /d D:\work\site |
Microsoft Learn · cd | |
mdmd <path> |
创建目录;命令扩展模式下可一次创建多级目录。 | md D:\backup\2026-10-23 |
Microsoft Learn · md | |
rd /s /qrd /s /q <path>危险不会进入回收站;确认路径中没有通配符或变量展开错误。
|
递归删除目录且不询问,等效于删除整棵目录树。 | rd /s /q D:\temp\old-build |
Microsoft Learn · rd | |
del /f /qdel /f /q <files>危险通配符会批量删除文件,执行前先用 dir 预览匹配范围。
|
强制删除只读文件并跳过确认;不支持直接删除目录。 | del /f /q D:\temp\*.log |
Microsoft Learn · del | |
copycopy <source> <dest> [/y] |
复制单个文件或合并文件;目录树请用 xcopy 或 robocopy。 | copy /y .\config.ini D:\backup\config.ini |
Microsoft Learn · copy | |
movemove <source> <dest> |
移动文件或重命名目录;跨卷移动会先复制再删除。 | move D:\build\app.exe D:\release\app.exe |
Microsoft Learn · move | |
renren <old-name> <new-name> |
重命名文件或目录;新名称不能带路径。 | ren app.log app-2026-10-23.log |
Microsoft Learn · ren | |
attribattrib [+r|-r] [+h|-h] [+s|-s] <path> |
查看或修改只读、隐藏、系统属性。 | attrib +h .\private.txt |
Microsoft Learn · attrib | |
wherewhere <pattern> [/r <dir>] |
按 PATH 或指定目录查找可执行文件位置。 | where python |
Microsoft Learn · where | |
findstrfindstr [/s] [/i] [/n] <pattern> <files> |
在文件中搜索文本或正则;/s 递归,/n 显示行号。 | findstr /s /i /n "ERROR" D:\logs\*.log |
Microsoft Learn · findstr | |
fcfc <file1> <file2> |
逐行比较两个文件并输出差异。 | fc .\config.old .\config.new |
Microsoft Learn · fc | |
typetype <file> |
把文本文件内容输出到控制台;大文件建议用 more 分页。 | type C:\Windows\win.ini |
Microsoft Learn · type | |
tree /ftree [/f] [path] |
以树形显示目录结构;/f 同时列出文件名。 | tree /f D:\project |
Microsoft Learn · tree | |
robocopy /mirrobocopy <source> <dest> /MIR危险/MIR 会删除目标端多余文件;先加 /L 预览,确认源和目标没有写反。
|
镜像复制目录,使目标与源一致,并删除目标中多余文件。 | robocopy D:\site E:\backup\site /MIR /R:2 /W:2 |
Microsoft Learn · robocopy | |
mklink /dmklink /d <link> <target> |
创建目录符号链接;/j 创建目录联接,/h 创建硬链接。 | mklink /d C:\site D:\releases\current |
Microsoft Learn · mklink | |
forfilesforfiles /p <dir> /s /m <pattern> /d -<days> /c "cmd /c del @path"危险把 echo 换成 del 前先预览 @path,确认匹配范围和保留天数。
|
按修改日期批量处理文件,常用来清理旧日志。 | forfiles /p D:\logs /s /m *.log /d -30 /c "cmd /c echo @path" |
Microsoft Learn · forfiles | |
Get-ChildItemGet-ChildItem [-Path <path>] [-Recurse] |
列出文件和目录;-Recurse 递归遍历。 | Get-ChildItem C:\Logs -Recurse -File | Sort-Object LastWriteTime -Descending |
Microsoft Learn · Get-ChildItem | |
Get-ContentGet-Content <path> [-Tail <n>] |
读取文本文件;-Tail 适合查看日志末尾。 | Get-Content .\app.log -Tail 50 -Wait |
Microsoft Learn · Get-Content | |
Select-StringSelect-String -Pattern <regex> -Path <files> |
在文件中搜索文本或正则,类似 grep。 | Select-String -Pattern 'ERROR' -Path .\*.log |
Microsoft Learn · Select-String | |
Remove-ItemRemove-Item <path> [-Recurse] [-Force]危险删除后默认不进入回收站;先确认路径和备份。
|
删除文件或目录;-Recurse 删除目录树。 | Remove-Item .\temp -Recurse -Force |
Microsoft Learn · Remove-Item | |
Get-Volume |
查看卷、文件系统、剩余空间和健康状态。 | Get-Volume | Select-Object DriveLetter, FileSystemLabel, SizeRemaining, Size |
Microsoft Learn · Get-Volume | |
Get-Disk |
查看磁盘编号、分区表和联机状态,为 diskpart 操作前的只读检查。 | Get-Disk |
Microsoft Learn · Get-Disk | |
chkdskchkdsk <volume> [/scan] [/f] |
检查磁盘错误;/scan 在线扫描,/f 修复通常需要锁定卷。 | chkdsk C: /scan |
Microsoft Learn · chkdsk | |
diskpart危险clean 会清除分区表。必须确认 select disk 的编号。
|
交互式磁盘分区工具;list disk/select disk/clean 等操作风险极高。 | diskpart (先执行 list disk,确认磁盘编号) |
Microsoft Learn · diskpart | |
formatformat <volume> [/fs:<fs>] [/q]危险格式化会清除目标卷数据,不能只靠撤销恢复。
|
格式化卷并清除其中数据。 | format D: /fs:NTFS /q |
Microsoft Learn · format | |
Test-PathTest-Path <path> |
检查文件、目录或注册表路径是否存在,返回布尔值。 | Test-Path .\config.json |
Microsoft Learn · Test-Path | |
Copy-ItemCopy-Item <source> <dest> [-Recurse] |
复制文件或目录;-Recurse 用于目录树。 | Copy-Item .\site\* D:\backup\site\ -Recurse |
Microsoft Learn · Copy-Item | |
Compress-ArchiveCompress-Archive -Path <items> -DestinationPath <zip> |
把文件或目录打包为 ZIP;同名目标默认可能覆盖。 | Compress-Archive -Path .\site\* -DestinationPath .\site.zip -Force |
Microsoft Learn · Compress-Archive | |
xcopyxcopy <source> <dest> /E /I /H /Y |
CMD 复制目录树;/E 含空目录,/I 自动按目录处理目标。 | xcopy D:\work E:\backup\work /E /I /H /Y |
Microsoft Learn · xcopy | |
Get-PartitionGet-Partition [-DiskNumber <n>] |
查看分区编号、盘符、大小和类型,为磁盘操作前确认目标。 | Get-Partition | Select-Object DiskNumber, PartitionNumber, DriveLetter, Size |
Microsoft Learn · Get-Partition | |
Format-VolumeFormat-Volume -DriveLetter <letter> -FileSystem NTFS危险格式化会清除目标卷所有数据,确认盘符前不要执行。
|
PowerShell 格式化卷;会清除目标卷数据。 | Format-Volume -DriveLetter D -FileSystem NTFS -NewFileSystemLabel Data |
Microsoft Learn · Format-Volume |
维护与恢复
20 条系统文件修复按“SFC → DISM → 重启”的顺序执行;修改启动项前先导出配置。
| 命令 / 语法 | 说明 | 示例 | 平台 | 来源 |
|---|---|---|---|---|
sfc /scannow |
扫描并修复受保护的 Windows 系统文件,需要管理员权限。 | sfc /scannow |
Microsoft Learn · sfc | |
DISM /Online /Cleanup-Image /RestoreHealth |
修复 Windows 映像组件存储;常与 SFC 配合。 | DISM /Online /Cleanup-Image /RestoreHealth |
Microsoft Learn · DISM | |
gpupdate /force |
强制刷新组策略;部分策略需要注销或重启。 | gpupdate /force |
Microsoft Learn · gpupdate | |
whoami /all |
查看当前用户、组、权限和登录标识。 | whoami /all |
Microsoft Learn · whoami | |
shutdown /r /t 0shutdown /r /t <seconds>危险会中断所有用户会话;生产机需先走变更流程。
|
立即重启或延时重启;默认会提示关闭应用。 | shutdown /r /t 60 |
Microsoft Learn · shutdown | |
bcdeditbcdedit [/enum] [/export <file>]危险修改启动项前先 bcdedit /export 备份。
|
查看或修改启动配置数据;误改可能导致系统无法启动。 | bcdedit /enum |
Microsoft Learn · bcdedit | |
reg deletereg delete <key> [/v <value>] [/f]危险注册表误删可能破坏应用或系统登录,先导出备份。
|
删除注册表键或值;/f 跳过确认。 | reg query HKCU\Software\Vendor\App |
Microsoft Learn · reg | |
wevtutil qewevtutil qe System /c:<count> /rd:true /f:text |
从命令行读取事件日志,适合无 PowerShell 的恢复环境。 | wevtutil qe System /c:20 /rd:true /f:text |
Microsoft Learn · wevtutil | |
gpresult /hgpresult /h <report.html> /f |
生成组策略结果报告,确认实际生效的策略和来源。 | gpresult /h .\gp-report.html /f |
Microsoft Learn · gpresult | |
powercfg /batteryreportpowercfg /batteryreport /output <report.html> |
生成电池健康与使用报告,包含设计容量和最近充放电记录。 | powercfg /batteryreport /output .\battery.html |
Microsoft Learn · powercfg | |
reagentc /info |
查看 Windows 恢复环境状态和恢复分区位置。 | reagentc /info |
Microsoft Learn · reagentc | |
sfc /verifyonly |
只校验受保护的系统文件,不自动修复,适合先确认问题范围。 | sfc /verifyonly |
Microsoft Learn · sfc | |
DISM /CheckHealthDISM /Online /Cleanup-Image /CheckHealth |
快速检查组件存储是否被标记为损坏,不做修复。 | DISM /Online /Cleanup-Image /CheckHealth |
Microsoft Learn · DISM | |
DISM /ScanHealthDISM /Online /Cleanup-Image /ScanHealth |
扫描组件存储损坏,耗时较长但不修改系统。 | DISM /Online /Cleanup-Image /ScanHealth |
Microsoft Learn · DISM | |
DISM /StartComponentCleanupDISM /Online /Cleanup-Image /StartComponentCleanup危险清理后无法卸载已安装更新;先确认回滚需求。
|
清理被取代的组件版本,释放 WinSxS 空间。 | DISM /Online /Cleanup-Image /StartComponentCleanup |
Microsoft Learn · DISM | |
bootrec /rebuildbcd危险只应在 WinRE 中操作;误改启动配置可能导致系统无法启动。
|
在恢复环境中重建启动配置数据中的 Windows 启动项。 | bootrec /rebuildbcd |
SS64 · bootrec | |
shutdown /a |
中止正在倒计时的关机或重启计划。 | shutdown /a |
Microsoft Learn · shutdown | |
powercfg /energypowercfg /energy /output <report.html> |
生成能耗诊断报告,定位电源、驱动和睡眠问题。 | powercfg /energy /output D:\backup\energy.html |
Microsoft Learn · powercfg | |
powercfg /sleepstudypowercfg /sleepstudy /output <report.html> |
生成睡眠研究报告,分析 Modern Standby 耗电。 | powercfg /sleepstudy /output D:\backup\sleep.html |
Microsoft Learn · powercfg | |
Get-WindowsOptionalFeatureGet-WindowsOptionalFeature -Online [-FeatureName <name>] |
查询 Windows 可选功能及启用状态,常与 DISM 配合。 | Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All |
Microsoft Learn · Get-WindowsOptionalFeature |
包管理与脚本
24 条先查帮助再执行;批量安装、升级或远程下载前确认来源和签名。
| 命令 / 语法 | 说明 | 示例 | 平台 | 来源 |
|---|---|---|---|---|
helphelp [command] |
列出 CMD 内置命令或查看指定命令的简要帮助。 | help robocopy |
Microsoft Learn · help | |
cls |
清空控制台屏幕,不影响命令历史和环境变量。 | cls |
Microsoft Learn · cls | |
echoecho <text> | echo off |
输出文本或控制批处理回显;@echo off 常用于脚本首行。 | echo Build started at %TIME% |
Microsoft Learn · echo | |
exitexit [/b <code>] |
退出当前 CMD 或批处理;/b 只退出当前批处理脚本。 | exit /b 0 |
Microsoft Learn · exit | |
titletitle <text> |
修改当前控制台窗口标题,便于区分多个终端。 | title Build Worker |
Microsoft Learn · title | |
colorcolor <background><foreground> |
修改控制台前后景颜色;颜色值为十六进制 0-F。 | color 0A |
Microsoft Learn · color | |
setset [name[=[value]]] |
查看或设置当前会话的环境变量;不带参数列出全部变量。 | set PATH |
Microsoft Learn · set | |
setxsetx <name> <value> [/m]危险setx 会永久写入环境变量;误改 PATH 可能影响后续登录。
|
持久化用户或系统环境变量;/m 需要管理员权限。 | setx APP_HOME D:\apps\demo |
Microsoft Learn · setx | |
for /ffor /f "tokens=*" %%i in (<file>) do <command> |
逐行读取文件或命令输出,是 CMD 批处理解析文本的核心写法。 | for /f "tokens=*" %%i in (servers.txt) do ping -n 1 %%i |
Microsoft Learn · for | |
if existif exist <path> (<command>) else (<command>) |
按文件、目录或驱动器是否存在执行分支。 | if exist D:\backup (echo OK) else (echo MISSING) |
Microsoft Learn · if | |
reg queryreg query <key> [/v <value>] [/s] |
读取注册表键和值;/s 递归查询子键。 | reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion |
Microsoft Learn · reg | |
reg addreg add <key> [/v <value>] [/t <type>] [/d <data>] [/f]危险注册表错误修改可能破坏应用或系统登录,先 reg export 备份。
|
新增或修改注册表值;/f 跳过确认。 | reg add HKCU\Software\Demo /v Enabled /t REG_DWORD /d 1 /f |
Microsoft Learn · reg | |
reg exportreg export <key> <file.reg> [/y] |
导出注册表分支,作为修改前的备份。 | reg export HKCU\Software\Demo D:\backup\demo.reg /y |
Microsoft Learn · reg | |
reg importreg import <file.reg>危险导入会直接改注册表;确认 .reg 来源和内容后再执行。
|
导入 .reg 文件,覆盖对应的注册表键值。 | reg import D:\backup\demo.reg |
Microsoft Learn · reg | |
winget searchwinget search <keyword> |
在 WinGet 源中搜索应用,确认包 ID 后再安装。 | winget search 7zip |
Microsoft Learn · WinGet | |
winget installwinget install --id <package-id> -e危险安装前确认发布者和包 ID,避免安装同名或仿冒软件。
|
按精确包 ID 安装应用;-e 表示 ID 精确匹配。 | winget install --id 7zip.7zip -e |
Microsoft Learn · WinGet | |
winget listwinget list [--id <package-id>] |
列出已安装应用和可用的升级版本。 | winget list --id 7zip.7zip |
Microsoft Learn · WinGet | |
winget upgradewinget upgrade [--id <package-id>] [--all] |
升级指定应用或全部可升级应用。 | winget upgrade --id 7zip.7zip -e |
Microsoft Learn · WinGet | |
winget uninstallwinget uninstall --id <package-id> -e危险卸载会移除应用及其配置,先确认没有业务依赖。
|
按精确包 ID 卸载应用。 | winget uninstall --id 7zip.7zip -e |
Microsoft Learn · WinGet | |
Get-CommandGet-Command <name> [-All] |
查找命令、别名、函数和可执行文件的实际来源。 | Get-Command ping -All |
Microsoft Learn · Get-Command | |
Get-HelpGet-Help <command> [-Full] [-Examples] |
查看 cmdlet 的参数、示例和详细说明。 | Get-Help Get-ChildItem -Examples |
Microsoft Learn · Get-Help | |
Update-HelpUpdate-Help [-Force] |
下载并更新本机 PowerShell 帮助内容。 | Update-Help -Force |
Microsoft Learn · Update-Help | |
Invoke-WebRequestInvoke-WebRequest <url> -OutFile <path> |
通过 HTTP 下载文件或读取网页;会自动解析部分响应内容。 | Invoke-WebRequest https://zuhejian.com/ -OutFile .\site.html |
Microsoft Learn · Invoke-WebRequest | |
Export-CsvExport-Csv -Path <file> -NoTypeInformation -Encoding UTF8 |
把对象导出为 CSV;-NoTypeInformation 去掉首行类型注释。 | Get-Process | Select-Object Name, CPU, WorkingSet | Export-Csv .\processes.csv -NoTypeInformation -Encoding UTF8 |
Microsoft Learn · Export-Csv |
没有匹配的命令,试试更短的关键词或切换平台。
来源:Microsoft Learn、man7、GNU 手册及各发行版官方文档;更新 2026-10-23。