跨平台運維常需在 Linux Shell 與 Windows PowerShell/CMD 間切換。本表整理核心檔案、進程、網路、環境變數、說明系統等高頻指令對照,加速肌肉記憶轉換。
| 功能 | Linux (Bash) | Windows (PowerShell) | Windows (CMD) |
| 顯示目前目錄 | pwd | Get-Location / pwd | cd |
| 列出內容 | ls -la | Get-ChildItem -Force / ls -Force | dir /a |
| 建立目錄 | mkdir -p a/b/c | New-Item -ItemType Directory -Path a/b/c | mkdir a\b\c |
| 切換目錄 | cd /path | Set-Location / cd /path | cd /d X:\path |
| 上一層目錄 | cd .. | cd .. | cd .. |
| 複製檔案 | cp src dst | Copy-Item src dst | copy src dst |
| 複製目錄 | cp -r src/ dst/ | Copy-Item src/ dst/ -Recurse | xcopy /E /I src\ dst\ |
| 移動/重命名 | mv old new | Move-Item old new / Rename-Item | move old new / ren old new |
| 刪除檔案 | rm file | Remove-Item file | del file |
| 刪除目錄 | rm -rf dir/ | Remove-Item dir/ -Recurse -Force | rmdir /s /q dir\ |
| 建立空檔 | touch file | New-Item file -ItemType File | type nul > file |
| 檢視檔案 | cat file / less file | Get-Content file / more file | type file / more file |
| 搜尋檔案 | find / -name "*.log" | Get-ChildItem -Recurse -Filter *.log | dir /s /b *.log |
| 內容搜尋 | grep "pattern" file | Select-String "pattern" file | findstr "pattern" file |
| 功能 | Linux | PowerShell | CMD |
| 主機名稱 | hostname | $env:COMPUTERNAME / hostname | hostname |
| 作業系統版本 | cat /etc/os-release / uname -a | [System.Environment]::OSVersion.Version / systeminfo | ver / systeminfo |
| CPU 資訊 | cat /proc/cpuinfo / lscpu | Get-CimInstance Win32_Processor | wmic cpu get / systeminfo |
| 記憶體資訊 | free -h / cat /proc/meminfo | Get-CimInstance Win32_OperatingSystem | select TotalVisibleMemorySize,FreePhysicalMemory | systeminfo | find "Memory" |
| 磁碟使用率 | df -h | Get-CimInstance Win32_LogicalDisk | ft DeviceID,@{n='Size(GB)';e={"{0:N1}" -f ($_.Size/1GB)}},@{n='Free(GB)';e={"{0:N1}" -f ($_.FreeSpace/1GB)}} | wmic logicaldisk get size,freespace,caption |
| 目錄大小 | du -sh dir | (Get-ChildItem dir -Recurse | Measure-Object -Property Length -Sum).Sum | — |
| 即時監控 | top / htop / glances | Get-Process | Sort-Object CPU -Desc | Select -First 10 | taskmgr |
| 功能 | Linux | PowerShell | CMD |
| IP 設定 | ip a / ifconfig | Get-NetIPConfiguration / ipconfig | ipconfig /all |
| 測試連通 | ping host / nc -zv host port | Test-Connection host / Test-NetConnection host -Port port | ping host / telnet host port |
| 路由追蹤 | traceroute host / tracepath host | Test-NetConnection host -TraceRoute | tracert host |
| 連線埠監聽 | ss -antulp / netstat -antulp | Get-NetTCPConnection -State Listen | netstat -an | find "LISTENING" |
| 下載檔案 | wget url / curl -O url | Invoke-WebRequest -OutFile file url | curl url -o file (Win10+) |