⭐ Windows CMD / PowerShell / Linux 对照表
1. 查看当前路径
- CMD:
cd - PowerShell:
Get-Location或缩写pwd - Linux:
pwd
小提示:PowerShell 的 pwd 是对 Linux 的一种"致敬",但实质是它自己的 Get-Location。
2. 列出当前目录文件
- CMD:
dir - PowerShell:
Get-ChildItem或缩写ls - Linux:
ls
PowerShell 里的 ls 是个"拟态动物"------其实它还是 Get-ChildItem。
3. 切换目录
- CMD:
cd - PowerShell:
Set-Location或cd - Linux:
cd
PowerShell 倾向于长名字,但为了不吓到来自 Unix 的开发者,它也准备了 cd。
4. 创建目录
- CMD:
mkdir - PowerShell:
New-Item -ItemType Directory - Linux:
mkdir
PowerShell 的长名字像是一本官僚文书,但功能完全一致。
5. 删除文件
- CMD:
del file.txt - PowerShell:
Remove-Item file.txt或缩写rm file.txt - Linux:
rm file.txt
PowerShell 同名命令 rm 只是一个"外衣",里面还是它的 cmdlet。
6. 删除目录
- CMD:
rmdir /s - PowerShell:
Remove-Item dir -Recurse - Linux:
rm -rf dir
Linux 的 rm -rf 是灭霸响指,别乱试。
7. 复制文件
- CMD:
copy - PowerShell:
Copy-Item或缩写cp - Linux:
cp
PowerShell 的 cp 就像给 Bash 用户的一块安慰糖。
8. 移动、重命名
- CMD:
move - PowerShell:
Move-Item或mv - Linux:
mv
9. 查看文件内容
- CMD:
type file.txt - PowerShell:
Get-Content file.txt或cat file.txt - Linux:
cat file.txt
PowerShell 的 cat 是伪装的,逻辑属于 Get-Content。
10. 输出并分页阅读
- CMD:
more - PowerShell:
more - Linux:
more或更高级的less
Linux 的 less 是"more 的进化体"。
11. 环境变量
查询:
- CMD:
set - PowerShell:
Get-ChildItem Env: - Linux:
env
设置:
- CMD:
setx VAR value - PowerShell:
$env:VAR="value" - Linux:
export VAR=value
PowerShell 用类似访问"虚拟硬盘"的方式管理环境变量。
12. 网络连通性测试
- CMD:
ping - PowerShell:
Test-Connection或ping - Linux:
ping
PowerShell 的 Test-Connection 能输出对象化的数据,比传统 ping 花哨。
13. 清屏
- CMD:
cls - PowerShell:
Clear-Host或cls - Linux:
clear
14. 进程查看
- CMD:
tasklist - PowerShell:
Get-Process - Linux:
ps aux
如果你喜欢统计、过滤,PowerShell 会是你的天堂。
15. 杀进程
- CMD:
taskkill /IM xxx.exe - PowerShell:
Stop-Process -Name xxx - Linux:
kill -9 pid
Linux 的 kill -9 是终极狠招:不讲情面,直接终止。
16. 查看网络连接
- CMD:
netstat - PowerShell:
Get-NetTCPConnection - Linux:
netstat或ss
Linux 的 ss 是新生代,更快更准。
17. 执行脚本
- CMD:直接运行
.cmd/.bat - PowerShell:
./script.ps1(可能需要调整执行策略) - Linux:
./script.sh
PowerShell 默认禁止执行脚本,这是出于安全考虑,需要:
Set-ExecutionPolicy RemoteSigned
🌟 小总结:三者的哲学差异
Bash 喜欢"短小精悍的魔法咒语"。
CMD 喜欢"老派 DOS 风格的命令"。
PowerShell 喜欢"面向对象的长名字咒文"。