萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

Linux 與 Windows 基礎指令對照表:跨平台運維速查手冊

跨平台運維常需在 Linux Shell 與 Windows PowerShell/CMD 間切換。本表整理核心檔案、進程、網路、環境變數、說明系統等高頻指令對照,加速肌肉記憶轉換。

檔案與目錄操作

功能Linux (Bash)Windows (PowerShell)Windows (CMD)
顯示目前目錄pwdGet-Location / pwdcd
列出內容ls -laGet-ChildItem -Force / ls -Forcedir /a
建立目錄mkdir -p a/b/cNew-Item -ItemType Directory -Path a/b/cmkdir a\b\c
切換目錄cd /pathSet-Location / cd /pathcd /d X:\path
上一層目錄cd ..cd ..cd ..
複製檔案cp src dstCopy-Item src dstcopy src dst
複製目錄cp -r src/ dst/Copy-Item src/ dst/ -Recursexcopy /E /I src\ dst\
移動/重命名mv old newMove-Item old new / Rename-Itemmove old new / ren old new
刪除檔案rm fileRemove-Item filedel file
刪除目錄rm -rf dir/Remove-Item dir/ -Recurse -Forcermdir /s /q dir\
建立空檔touch fileNew-Item file -ItemType Filetype nul > file
檢視檔案cat file / less fileGet-Content file / more filetype file / more file
搜尋檔案find / -name "*.log"Get-ChildItem -Recurse -Filter *.logdir /s /b *.log
內容搜尋grep "pattern" fileSelect-String "pattern" filefindstr "pattern" file

進程管理

功能LinuxPowerShellCMD
列出進程ps aux / ps -efGet-Process / pstasklist
依名稱篩選ps aux | grep nameGet-Process -Name name*tasklist /fi "imagename eq name*"
終止進程 (PID)kill PID / kill -9 PIDStop-Process -Id PID -Forcetaskkill /PID PID /F
終止進程 (名稱)killall name / pkill nameStop-Process -Name name -Forcetaskkill /IM name.exe /F
前/後台切換Ctrl+Z, bg, fg, jobsStart-Job / Receive-Job—
進程樹pstree -pGet-Process | Format-Table Id,ParentId,Name—

系統資訊與資源監控

功能LinuxPowerShellCMD
主機名稱hostname$env:COMPUTERNAME / hostnamehostname
作業系統版本cat /etc/os-release / uname -a[System.Environment]::OSVersion.Version / systeminfover / systeminfo
CPU 資訊cat /proc/cpuinfo / lscpuGet-CimInstance Win32_Processorwmic cpu get / systeminfo
記憶體資訊free -h / cat /proc/meminfoGet-CimInstance Win32_OperatingSystem | select TotalVisibleMemorySize,FreePhysicalMemorysysteminfo | find "Memory"
磁碟使用率df -hGet-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 / glancesGet-Process | Sort-Object CPU -Desc | Select -First 10taskmgr

網路與連線

功能LinuxPowerShellCMD
IP 設定ip a / ifconfigGet-NetIPConfiguration / ipconfigipconfig /all
測試連通ping host / nc -zv host portTest-Connection host / Test-NetConnection host -Port portping host / telnet host port
路由追蹤traceroute host / tracepath hostTest-NetConnection host -TraceRoutetracert host
連線埠監聽ss -antulp / netstat -antulpGet-NetTCPConnection -State Listennetstat -an | find "LISTENING"
下載檔案wget url / curl -O urlInvoke-WebRequest -OutFile file urlcurl url -o file (Win10+)

環境變數與別名

功能LinuxPowerShellCMD
檢視所有env / printenvGet-ChildItem Env: / dir env:set
檢視單一echo $VAR$env:VARecho %VAR%
設定 (當前 session)export VAR=value$env:VAR = 'value'set VAR=value
永久設定 (使用者)~/.bashrc / ~/.profile$PROFILE (CurrentUserAllHosts)setx VAR value
別名alias ll='ls -l'Set-Alias ll Get-ChildItemdoskey ll=dir

獲取說明

  • Linux:man 指令、指令 --help、info 指令。
  • PowerShell:Get-Help 指令 -Full、指令 -?。
  • CMD:指令 /?、help 指令。

建議將此表匯出為 PDF 或 Markdown 置於桌面,逐項實操 2-3 遍,即可建立跨平台指令肌肉記憶。

copyright © 萬盛學電腦網 all rights reserved