cmd、powershell、linux下命令对比

⭐ 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-Locationcd
  • 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-Itemmv
  • Linux:mv

9. 查看文件内容

  • CMD:type file.txt
  • PowerShell:Get-Content file.txtcat 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-Connectionping
  • Linux:ping

PowerShell 的 Test-Connection 能输出对象化的数据,比传统 ping 花哨。


13. 清屏

  • CMD:cls
  • PowerShell:Clear-Hostcls
  • 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:netstatss

Linux 的 ss 是新生代,更快更准。


17. 执行脚本

  • CMD:直接运行 .cmd / .bat
  • PowerShell:./script.ps1(可能需要调整执行策略)
  • Linux:./script.sh

PowerShell 默认禁止执行脚本,这是出于安全考虑,需要:

复制代码
Set-ExecutionPolicy RemoteSigned

🌟 小总结:三者的哲学差异

Bash 喜欢"短小精悍的魔法咒语"。

CMD 喜欢"老派 DOS 风格的命令"。

PowerShell 喜欢"面向对象的长名字咒文"。

相关推荐
tntxia13 小时前
linux curl命令详解_curl详解
linux
扛枪的书生15 小时前
Linux 网络管理器用法速查
linux
SkyWalking中文站17 小时前
认识 Horizon UI · 1/17:SkyWalking 新一代可观测性控制台
运维·前端·监控
顺风尿一寸18 小时前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
雪梨酱QAQ20 小时前
Kubeneters HA Cluster部署
运维
江华森1 天前
Spring Cloud 微服务全栈实战:从 Eureka 到 Docker Compose 一文贯通
运维
江华森1 天前
Matplotlib 数据绘图基础入门
运维
XIAOHEZIcode1 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
江华森1 天前
NumPy 数值计算基础入门
运维
唐青枫1 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux