Skip to content

开发者命令行速查表:CMD / PowerShell / Shell(bash·zsh) ​

适用场景:日常开发、排障、服务器运维。三栏分别是 Windows 的 cmd、Windows 的 PowerShell、以及 Linux / macOS 的 bash / zsh。 小提示:PowerShell 内置了大量「别名」(ls、cp、rm、cat、pwd、mv…),大多和 Shell 写法一致,所以中间栏常给「原生写法 / 别名」两种。

任务CMDPowerShellShell (bash / zsh)
显示当前目录cd
echo %cd%
Get-Location / pwdpwd
列出文件dirGet-ChildItem / ls / dirls -la
切换目录cd 路径Set-Location 路径 / cd 路径cd 路径
返回上级目录cd ..cd ..cd ..
新建目录mkdir 名New-Item -ItemType Directory 名 / mkdir 名mkdir 名
新建空文件type nul > 文件New-Item 文件 / ni 文件touch 文件
复制文件copy 源 目标Copy-Item 源 目标 / cp 源 目标cp 源 目标
移动 / 重命名move 源 目标Move-Item 源 目标 / mv 源 目标mv 源 目标
删除文件del 文件Remove-Item 文件 / rm 文件rm 文件
删除目录(递归)rmdir /s /q 目录Remove-Item 目录 -Recurse -Force / rm -rf 目录rm -rf 目录
查看文件内容type 文件Get-Content 文件 / cat 文件cat 文件
less 文件
查找文件dir /s /b 名Get-ChildItem -Recurse -Filter 名find . -name 名
文本搜索findstr "词" 文件Select-String "词" 文件grep -rn "词" .
查本机 IPipconfigipconfig / Get-NetIPAddressip a / ifconfig
网络连通测试ping 主机ping 主机 / Test-Connection 主机ping 主机
查看端口/连接netstat -anoGet-NetTCPConnectionss -tulpn
netstat -tulpn
下载文件curl -O url
(Win10+)
Invoke-WebRequest -Uri url -OutFile f / curl -O urlcurl -O url
wget url
进程列表tasklistGet-Process / psps aux
结束进程taskkill /PID 123 /FStop-Process -Id 123 / kill 123kill -9 123
清屏clsClear-Host / cls / clearclear
查看环境变量set / echo %VAR%Get-ChildItem env: / $env:VARenv / echo $VAR
临时设环境变量set VAR=值$env:VAR="值"export VAR=值
解压tar -xf 包Expand-Archive 包 目标tar -xzf 包
unzip 包
压缩tar -cf 包 目录Compress-Archive 目录 包tar -czf 包 目录
改文件权限icacls 文件 /grant ...icacls 文件 ...chmod 755 文件
chown 用户 文件
SSH 远程登录ssh user@hostssh user@hostssh user@host
Git 操作git ...git ...git ...
查命令帮助命令 /?Get-Help 命令 / 命令 -?命令 --help / man 命令

记忆口诀 ​

  • Shell 是通用的:bash / zsh 在 Linux 和 macOS 上几乎一样;ls / cp / mv / rm / cat / grep / chmod / ssh / git 跨平台通用。
  • PowerShell 兼容大部分 Shell 别名:ls、cp、rm、cat、pwd、mv、curl 在 PowerShell 里直接能用,不必背 Get-ChildItem 这种长名。
  • cmd 最老最窄:文本处理弱、没有 grep/chmod/ssh(旧版),适合基础操作;新机器建议直接用 PowerShell 或 Windows Terminal 里的 WSL。
  • 想用 Linux 命令又只在 Windows:装 WSL(wsl --install),Windows Terminal 里开 Ubuntu 标签页,上面整列 Shell 命令原地可用。

推荐组合(开发者日常) ​

  1. Windows:装 Windows Terminal + 设默认,里面开 PowerShell 标签页(写脚本强)和 WSL/Ubuntu 标签页(跑 Linux 命令)。
  2. 用 SSH 配置连你的云服务器(如 dakago 部署机),一个窗口管理本地 + 远程。
  3. macOS / Linux:自带终端即可,命令与上方 Shell 列完全一致。