一、CMD 与 PowerShell 全⾯对⽐

概览

特性 CMD(命令提示符) PowerShell(Windows PowerShell)
历史起源 起源于 MS-DOS,功能基础 基于 .NET Framework/Core,结合面向对象思想
输出类型 纯文本输出 面向对象,返回 .NET 对象,支持属性和方法操作
脚本支持 支持批处理脚本 (.bat/.cmd) 支持高级脚本(.ps1)和模块化扩展
跨平台支持 不支持,仅限 Windows 系统 支持 Windows、Linux、macOS (PowerShell Core/7.x)
命令集扩展性 基础命令集 支持自定义模块、函数,兼容 Linux 命令
适合场景 文件管理、简单系统操作 高级任务自动化、复杂数据处理、跨平台操作

二、CMD 常⽤命令

命令 功能描述 示例
dir 显示当前目录下的文件和文件夹 dir
cd 切换工作目录 cd C:\Users
cls 清屏 cls
del 删除文件 del file.txt
copy 复制文件 copy source.txt dest.txt
move 移动文件 move source.txt folder\
mkdir 创建文件夹 mkdir NewFolder
rmdir 删除文件夹 rmdir /s /q folder
type 显示文件内容 type file.txt
ping 测试网络连接 ping www.google.com
ipconfig 查看网络配置 ipconfig
tasklist 查看运行的进程 tasklist
taskkill 终止进程 taskkill /PID 1234

三、PowerShell 常⽤命令

1. 基本⽂件和⽬录操作

功能 PowerShell 命令 示例
查看目录内容 Get-ChildItem Get-ChildItem
切换目录 Set-Location Set-Location C:\Users
删除文件/文件夹 Remove-Item Remove-Item file.txt
创建目录 New-Item New-Item -ItemType Directory -Name NewFolder
复制文件/文件夹 Copy-Item Copy-Item source.txt dest.txt
移动文件/文件夹 Move-Item Move-Item source.txt folder\
显示文件内容 Get-Content Get-Content file.txt

2. 系统和⽹络管理

功能 PowerShell 命令 示例
查看进程 Get-Process Get-Process
终止进程 Stop-Process Stop-Process -Name notepad
查看网络配置 Get-NetIPAddress Get-NetIPAddress
测试网络连接 Test-Connection Test-Connection www.google.com

3. ⾼级任务和脚本

功能 PowerShell 命令 示例
下载文件 Invoke-WebRequest Invoke-WebRequest -Uri "url" -OutFile "file"
解压缩文件 Expand-Archive Expand-Archive -Path archive.zip -DestinationPath folder
查看系统事件日志 Get-EventLog Get-EventLog -LogName System
获取服务状态 Get-Service Get-Service
启动服务 Start-Service Start-Service -Name wuauserv

四、PowerShell 对 Linux 命令的⽀持

PowerShell 在跨平台版本中支持许多 Linux 常用命令。这些命令实际上是别名,最终调用的是 PowerShell 自己的命令。

Linux 命令 PowerShell 等效命令 描述
ls Get-ChildItem 列出目录内容
cd Set-Location 切换目录
pwd Get-Location 显示当前路径
cp Copy-Item 复制文件或文件夹
mv Move-Item 移动文件或文件夹
rm Remove-Item 删除文件或文件夹
cat Get-Content 显示文件内容
echo Write-Output 输出内容
ps Get-Process 显示当前运行的进程
kill Stop-Process 终止进程
touch New-Item 创建空文件
man Get-Help 查看命令帮助文档
grep Select-String 查找字符串
curl Invoke-WebRequest 发送 HTTP 请求

五、CMD 和 PowerShell 命令对⽐速查

功能 CMD 命令 PowerShell 命令 Linux 命令等效
查看目录内容 dir Get-ChildItem ls
切换目录 cd Set-Location cd
显示当前路径 Get-Location pwd
删除文件/文件夹 del / rmdir Remove-Item rm
复制文件 copy Copy-Item cp
移动文件 move Move-Item mv
查看文件内容 type Get-Content cat
查找字符串 Select-String grep
测试网络连接 ping Test-Connection ping