Linux 命令大全
按用途分类的高频命令速查:文件、文本、进程、网络、系统、权限、包管理。
Key Points真正高频的只有二三十个:ls/cd/cp/mv/rm、grep/sed/awk、ps/top/kill、ss/curl、df/du/free、chmod/chown、systemctl。
文件与目录
| Command | Purpose | Example |
|---|---|---|
ls | List | ls -lah |
cd | Change dir | cd - |
cp / mv / rm | Copy / move / remove | cp -a src dst |
mkdir / rmdir | Make / remove dir | mkdir -p a/b/c |
ln -s | Symlink | ln -s /opt/x current |
find | Find by name/time/size | find . -name '*.log' |
tar | Archive | tar -czf a.tgz dir/ |
stat | File metadata | stat 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进程与系统
| Command | Purpose |
|---|---|
ps aux / ps -ef | Snapshot of processes |
top / htop | Live CPU/memory |
kill -15 PID | SIGTERM, graceful |
kill -9 PID | SIGKILL, cannot be caught |
pkill -f name | Kill by command line match |
systemctl status x | Service state |
journalctl -u x -f | Service logs |
free -h / uptime | Memory / 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包管理
| Family | Update | Install | Search |
|---|---|---|---|
| Debian/Ubuntu | apt update | apt install x | apt search x |
| RHEL/Rocky | dnf makecache | dnf install x | dnf search x |
| Alpine | apk update | apk add x | apk search x |
| Arch | pacman -Sy | pacman -S x | pacman -Ss x |
帮助
Bash
man ls
ls --help
help cd # shell 内建命令用 help
type ls
command -v nginxIn
man, press / to search, n for next, q to quit. It beats a web search and always matches the version you actually have.文件与目录
| 命令 | 用途 | 例子 |
|---|---|---|
ls | 列目录 | ls -lah |
cd | 切换目录 | cd - |
cp/mv/rm | 复制 / 移动 / 删除 | cp -a src dst |
mkdir/rmdir | 建 / 删目录 | mkdir -p a/b/c |
ln -s | 软链接 | ln -s /opt/x current |
find | 按名/时间/大小查找 | find . -name '*.log' |
tar | 打包 | tar -czf a.tgz dir/ |
stat | 文件元信息 | stat 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进程与系统
| 命令 | 用途 |
|---|---|
ps | 进程快照 |
top | 实时 CPU/内存 |
kill | SIGTERM,优雅退出 |
kill -9 | SIGKILL,无法捕获 |
pkill -f | 按命令行匹配杀 |
systemctl | 服务状态 |
journalctl | 服务日志 |
free/uptime | 内存 / 负载 |
df/du | 磁盘余量 / 占用 |
网络
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包管理
| 系 | 更新索引 | 安装 | 搜索 |
|---|---|---|---|
| Debian/Ubuntu | apt update | apt install x | apt search x |
| RHEL/Rocky | dnf makecache | dnf install x | dnf search x |
| Alpine | apk update | apk add x | apk search x |
| Arch | pacman -Sy | pacman -S x | pacman -Ss x |
帮助
Bash
man ls
ls --help
help cd # shell 内建命令用 help
type ls
command -v nginxman 里按 / 搜索、n 下一个、q 退出。记不住参数时 man 比搜索引擎快,而且一定是当前系统这个版本的行为。