在 Linux 日常運維中,快速掌握系統版本、資源使用、網路狀態與套件安裝情況,是排查問題的基礎。以下依情境整理常用指令。
uname -a head -n 1 /etc/issue cat /proc/cpuinfo hostname lspci -tv lsusb -tv lsmod env
free -m df -h du -sh 目錄名 grep MemTotal /proc/meminfo grep MemFree /proc/meminfo uptime cat /proc/loadavg
mount | column -t fdisk -l swapon -s hdparm -i /dev/hda dmesg | grep IDE
ifconfig iptables -L route -n netstat -lntp netstat -antp netstat -s
ps -ef top w id 用戶名 last cut -d: -f1 /etc/passwd cut -d: -f1 /etc/group crontab -l
chkconfig --list chkconfig --list | grep on rpm -qa
RPM 是 Red Hat 系列常用的套件管理工具,功能類似 Windows 的「新增或移除程式」,但更適合命令列環境。
rpm -qpi 套件.rpm rpm -qpl 套件.rpm rpm -ivh 套件.rpm rpm -ivh -replacepkgs 套件.rpm rpm -e 套件名 rpm -uvh 套件.rpm rpm -Va rpm -qf 檔案名
在 Debian 或 Ubuntu 系列中,apt-get 是常見的套件管理工具。
apt-get update apt-get install 套件名 apt-get remove 套件名 apt-get --purge remove 套件名 apt-get autoclean apt-get clean apt-get upgrade apt-get dist-upgrade apt-cache search 字串 dpkg -l 模式 aptitude apt-cache showpkg 套件 apt-cache show 套件 dpkg -S 檔案 dpkg -L 套件 apt-file search 檔案名
掌握這些指令,可以快速定位系統狀態、套件依賴與檔案歸屬,也能提升日常排錯效率。