Linux 命令大全

按用途分类的高频命令速查:文件、文本、进程、网络、系统、权限、包管理。

Beginner
Key Points真正高频的只有二三十个:ls/cd/cp/mv/rm、grep/sed/awk、ps/top/kill、ss/curl、df/du/free、chmod/chown、systemctl。

文件与目录

CommandPurposeExample
lsListls -lah
cdChange dircd -
cp / mv / rmCopy / move / removecp -a src dst
mkdir / rmdirMake / remove dirmkdir -p a/b/c
ln -sSymlinkln -s /opt/x current
findFind by name/time/sizefind . -name '*.log'
tarArchivetar -czf a.tgz dir/
statFile metadatastat file

文本处理

Bash
cat file                 # 全部输出
less file                # 分页查看
head -n 20 file          # 前 20 行
tail -f app.log          # 跟踪末尾
grep -rn "error" /var/log
sed -i 's/old/new/g' file
awk '{print $1, $3}' access.log
sort -k2 -n file | uniq -c | head
cut -d: -f1 /etc/passwd
wc -l file

进程与系统

CommandPurpose
ps aux / ps -efSnapshot of processes
top / htopLive CPU/memory
kill -15 PIDSIGTERM, graceful
kill -9 PIDSIGKILL, cannot be caught
pkill -f nameKill by command line match
systemctl status xService state
journalctl -u x -fService logs
free -h / uptimeMemory / load average
df -h / du -sh *Disk free / usage

网络

Bash
ip addr show
ss -lntp                 # 监听端口与进程
ping -c3 8.8.8.8
curl -sS -I https://example.com
curl -X POST -H 'Content-Type: application/json' -d '{"a":1}' http://127.0.0.1:8080/api
dig +short example.com
traceroute example.com
tcpdump -i eth0 port 80 -c 20

权限与用户

Bash
chmod 644 file
chown -R app:app /opt/app
id
useradd -m -s /bin/bash alice
usermod -aG sudo alice
passwd alice
sudo visudo

包管理

FamilyUpdateInstallSearch
Debian/Ubuntuapt updateapt install xapt search x
RHEL/Rockydnf makecachednf install xdnf search x
Alpineapk updateapk add xapk search x
Archpacman -Sypacman -S xpacman -Ss x

帮助

Bash
man ls
ls --help
help cd            # shell 内建命令用 help
type ls
command -v nginx
In man, press / to search, n for next, q to quit. It beats a web search and always matches the version you actually have.

Friends & Partners