Linux 命令參考
快速查找檔案管理、文字處理、進程、網路等必備 Linux/Unix 命令。
檔案 & 目錄
ls -laList files with details and hidden filescd <dir>Change directorypwdPrint working directorymkdir -p <dir>Create directory (and parents)rm -rf <dir>Remove directory recursively (careful!)cp -r <src> <dest>Copy files/directories recursivelymv <src> <dest>Move or rename file/directorytouch <file>Create empty file or update timestampfind . -name "*.txt"Find files by name patternfind . -type f -size +10MFind files larger than 10MBdu -sh *Show disk usage of each itemdf -hShow disk space usage文字處理
cat <file>Print file contentsless <file>Page through file (q to quit)head -n 20 <file>Show first 20 linestail -n 20 <file>Show last 20 linestail -f <file>Follow file (live log viewing)grep -r "pattern" .Search for pattern recursivelygrep -i "pattern" <file>Case-insensitive searchgrep -n "pattern" <file>Show line numbers in resultssed -i "s/old/new/g" <file>Replace text in file in-placeawk '{print $1}' <file>Print first columnsort <file>Sort lines alphabeticallysort -n -k2 <file>Sort numerically by 2nd columnuniq -cCount and deduplicate adjacent lineswc -l <file>Count lines in filecut -d"," -f1,3 <file>Cut specific columns (CSV)進程
ps auxList all running processestopInteractive process viewerhtopEnhanced process viewer (if installed)kill <pid>Terminate process by PIDkill -9 <pid>Force kill processpkill <name>Kill processes by namepgrep <name>Find PIDs by process namenohup <cmd> &Run command immune to hangups, in backgroundjobsList background jobsbg %1Resume job 1 in backgroundfg %1Bring job 1 to foreground權限 & 所有權
chmod 755 <file>Set rwxr-xr-x permissionschmod +x <file>Make file executablechown user:group <file>Change file owner and groupsudo <cmd>Run command as superusersudo -iSwitch to root shellsu - <user>Switch to another userumask 022Set default permission mask網路
curl -I <url>Show response headers onlycurl -L -o file <url>Download file following redirectswget <url>Download fileping <host>Test network connectivitytraceroute <host>Trace network path to hostnslookup <domain>DNS lookupdig <domain>Detailed DNS lookupnetstat -tulnShow listening portsss -tulnShow listening ports (modern)ssh user@hostConnect via SSHscp <file> user@host:/pathCopy file via SSHrsync -avz src/ user@host:dest/Sync files efficiently歸檔 & 壓縮
tar -czf archive.tar.gz <dir>Create gzip compressed archivetar -xzf archive.tar.gzExtract gzip archivetar -cjf archive.tar.bz2 <dir>Create bzip2 compressed archivezip -r archive.zip <dir>Create zip archiveunzip archive.zipExtract zip archivegzip <file>Compress file with gzipgunzip <file>.gzDecompress gzip file系統資訊
uname -aSystem and kernel informationcat /etc/os-releaseOS version informationfree -hMemory usageuptimeSystem uptime and loadwhoWho is logged inidCurrent user and group IDsenvShow environment variablesexport VAR=valueSet environment variablewhich <cmd>Find command pathhistoryCommand historyman <cmd>Manual page for a command關於本工具
Linux 命令參考提供了精選的必備 Linux/Unix 命令集合,按檔案目錄管理、文字處理、進程控制、權限與所有權、網路、歸檔壓縮和系統資訊七個類別整理。
每條命令都附有實際使用範例和簡潔說明。使用搜尋框可按命令名稱或描述關鍵詞快速篩選。
使用方法
- 在搜尋框中輸入命令名稱或關鍵詞。
- 捲動瀏覽各類別查找命令。
- 查看命令和說明,然後在終端機中使用。
- 將尖括號(<>)中的佔位符替換為實際值。
使用情境
適合撰寫部署腳本的 DevOps 工程師、除錯伺服器問題的系統管理員、查看檔案權限或進程的開發人員,以及學習 Linux 命令列基礎的初學者。
常見問題
- 尖括號(<>)代表什麼? 尖括號是佔位符。請將 <dir> 替換為實際目錄路徑,<file> 替換為檔案名稱,<pid> 替換為進程 ID,以此類推。
- 命令未找到怎麼辦? 某些命令(如 htop)預設未安裝。請使用套件管理器安裝(如 sudo apt install htop),或用 man 命令驗證是否可用。
- 使用 sudo 時需要注意什麼? sudo 以超級使用者權限執行命令。與 rm -rf 等破壞性命令結合使用可能造成不可逆的資料遺失。執行前務必仔細檢查。