以下是 Windows(CMD)、Mac(Terminal,基于 Unix)、Linux(终端,基于 Unix)常用终端命令的表格对照集合。不同系统的终端命令有相似性和差异性,Windows(CMD)使用 DOS 风格 命令,PowerShell 更接近 Linux Shell,而 Mac 和 Linux 终端命令基本相同。以下是关键命令的对比和总结:
1. 目录与文件管理
操作 Windows CMD Windows PowerShell Mac / Linux 终端 显示当前目录 cd
(无参数)Get-Location
或 pwd
pwd
切换目录 cd 目录名
cd 目录名
cd 目录名
返回上一级目录 cd ..
cd ..
cd ..
返回用户主目录 cd %USERPROFILE%
cd ~
cd ~
进入上一访问目录 ❌(不支持) cd -
cd -
列出目录文件 dir
Get-ChildItem
(ls
别名)ls -l
或 ls -al
创建文件 copy nul 文件名
New-Item 文件名
touch 文件名
创建目录 mkdir 目录名
New-Item -ItemType Directory 目录名
mkdir 目录名
复制文件 copy 源 目标
Copy-Item 源 目标
cp 源 目标
移动/重命名 move 源 目标
Move-Item 源 目标
mv 源 目标
删除文件 del 文件名
Remove-Item 文件名
rm 文件名
删除目录 rmdir /s 目录名
Remove-Item 目录名 -Recurse
rm -r 目录名
查找文件 dir /s /b 关键字
`Get-ChildItem -Recurse Select-String 关键字`
2. 历史命令管理
操作 Windows CMD Windows PowerShell Mac / Linux 终端 查看历史 doskey /history
history
或 Get-History
history
运行上一条命令 ↑
↑
↑
或 !!
运行历史中的第 N 条 ❌ Invoke-History N
!N
搜索历史命令 ❌ `Get-History Select-String "关键字"` 清空历史 关闭 CMD 后自动清除 Clear-History
history -c
立即保存历史 ❌ 自动保存 history -a
3. 进程管理
操作 Windows CMD Windows PowerShell Mac / Linux 终端 查看进程 tasklist
Get-Process
ps aux
结束进程 taskkill /PID 进程ID /F
Stop-Process -Id 进程ID
kill 进程ID
强制杀死进程 taskkill /IM 进程名 /F
Stop-Process -Name 进程名 -Force
kill -9 进程ID
监控进程 ❌ ❌ top
或 htop
4. 系统管理
操作 Windows CMD Windows PowerShell Mac / Linux 终端 关机 shutdown /s /t 0
Stop-Computer
shutdown -h now
重启 shutdown /r /t 0
Restart-Computer
reboot
查看磁盘使用 wmic logicaldisk get size,freespace,caption
Get-PSDrive
df -h
查看 CPU / 内存 wmic cpu get loadpercentage
Get-Counter '\Processor(_Total)\% Processor Time'
top
或 htop
5. 网络管理
操作 Windows CMD Windows PowerShell Mac / Linux 终端 查看 IP 地址 ipconfig
Get-NetIPAddress
ifconfig
(旧)/ ip a
(新)查看网络连接 netstat -an
Get-NetTCPConnection
netstat -an
Ping 目标 ping 目标
Test-Connection 目标
ping 目标
追踪路由 tracert 目标
Trace-Route 目标
traceroute 目标
连接 Wi-Fi ❌(图形界面设置) ❌(需要手动设置) nmcli dev wifi connect "WiFi名" password "密码"
6. 软件管理
操作 Windows CMD Windows PowerShell Mac / Linux 终端 安装软件 ❌(需手动下载) winget install 软件名
apt install 软件名
(Debian/Ubuntu) dnf install 软件名
(Fedora) brew install 软件名
(Mac)查找软件 ❌(不支持) winget search 关键字
apt search 关键字
(Linux) brew search 关键字
(Mac)卸载软件 ❌(需手动卸载) winget uninstall 软件名
apt remove 软件名
(Linux) brew uninstall 软件名
(Mac)
7. 其他常用命令
操作 Windows CMD Windows PowerShell Mac / Linux 终端 清屏 cls
Clear-Host
clear
显示时间 time /t
Get-Date -Format "HH:mm"
date "+%H:%M"
计算 MD5 certutil -hashfile 文件名 MD5
Get-FileHash 文件名 -Algorithm MD5
md5sum 文件名
计算 SHA256 certutil -hashfile 文件名 SHA256
Get-FileHash 文件名 -Algorithm SHA256
sha256sum 文件名
总结
Mac 和 Linux 终端命令几乎相同 ,但 Mac 依赖 brew
进行软件管理,而 Linux 依赖 apt/dnf/pacman
。
Windows CMD 功能较弱 ,很多操作不支持,例如搜索历史命令等,适合基本操作。
Windows PowerShell 更强大 ,与 Linux 终端相似,但命令格式不同,如 Get-Process
替代 ps aux
,Stop-Process
替代 kill
。
Windows 终端(Windows Terminal)+ PowerShell + WSL(Windows Subsystem for Linux) 是最佳体验。