📊 学习进度仪表盘
基于 localStorage 记录,无需登录,数据仅存本地浏览器
0
已完成课程
0%
平均测验分数
0
已复制命令数
0 min
预计学习时长
详细进度
📋 命令速查表
所有课程命令汇总,可搜索、复制
ssh-keygen -t ed25519 -C "your@email.com"
Generate Ed25519 SSH key pair
ssh-copy-id user@your-vps-ip
Copy public key to VPS for passwordless login
ssh user@your-vps-ip
Connect to VPS via SSH
cat ~/.ssh/config
View/edit SSH config for aliases
pwd
Print working directory
ls -la
List all files with details (long format, hidden)
cd /var/log
Change directory (absolute path)
cd ~
Go to home directory
cd ..
Go up one directory
tree -L 2 /etc
Show directory tree (install: apt install tree)
find /home -name '*.md' -type f
Find files by name recursively
touch file.txt
Create empty file or update timestamp
mkdir -p projects/web/{css,js,images}
Create nested directories (-p = parents)
cp file.txt backup.txt
Copy file
cp -r dir1 dir2
Copy directory recursively
mv old.txt new.txt
Move or rename file
rm file.txt
Remove file
rm -r dir
Remove directory recursively
cat file.txt
Display entire file
less large-file.log
Page through file (q to quit)
head -n 20 file.txt
First 20 lines
tail -f /var/log/syslog
Follow file (live updates, Ctrl+C to stop)
ls -l file.txt
Show permissions in long format
chmod 755 script.sh
Set permissions (owner=rwx, group=rx, other=rx)
chmod u+x script.sh
Add execute for user (symbolic)
chown ubuntu:ubuntu file.txt
Change owner and group
chown -R user:group dir/
Recursive ownership change
stat file.txt
Detailed file info including permissions
umask
Show default permission mask
grep 'error' /var/log/syslog
Search for pattern in file
grep -r 'TODO' /home/ubuntu/projects
Recursive search in directory
cat file.txt | grep 'pattern'
Pipe: pass output to another command
echo 'hello world' | sed 's/world/Linux/'
sed: stream editor (find/replace)
awk '{print $1}' /etc/passwd
awk: print first column (space-delimited)
cut -d: -f1,3 /etc/passwd
cut: extract columns by delimiter
sort file.txt | uniq
sort + uniq: remove duplicates
wc -l /etc/passwd
wc: count lines, words, chars
command > output.txt
Redirect stdout to file (overwrite)
command >> output.txt
Append stdout to file
command 2> errors.txt
Redirect stderr to file
command > out.txt 2>&1
Redirect both stdout and stderr
apt update
Refresh package index from repositories
apt upgrade
Upgrade all installed packages
apt install nginx
Install package
apt search nginx
Search packages by name/description
apt show nginx
Show detailed package info
apt remove nginx
Remove package (keep config)
apt purge nginx
Remove package + config files
apt autoremove
Remove unused dependencies
apt list --installed
List all installed packages
dpkg -l | grep nginx
Low-level: list installed packages matching
apt clean
Clear downloaded .deb cache
dnf install nginx
dnf equivalent (Fedora/RHEL/Rocky)
ps aux
List all processes (BSD syntax)
ps aux | grep nginx
Find processes by name
top
Interactive process viewer (q to quit)
htop
Enhanced interactive viewer (install: apt install htop)
sleep 100 &
Run command in background (&)
jobs
List background jobs
fg %1
Bring job 1 to foreground
bg %1
Resume stopped job in background
kill 12345
Send SIGTERM (graceful) to PID
kill -9 12345
Send SIGKILL (force) to PID
pkill -f 'sleep 100'
Kill by pattern (process name/command)
nohup long-script.sh &
Run immune to hangup (survives logout)
disown %1
Remove job from shell's job table (survives logout)
systemctl status nginx
Show service status
systemctl start nginx
Start service now
systemctl stop nginx
Stop service now
systemctl restart nginx
Restart service
systemctl reload nginx
Reload config without restart
systemctl enable nginx
Enable auto-start at boot
systemctl disable nginx
Disable auto-start at boot
systemctl is-enabled nginx
Check if enabled
systemctl list-units --type=service --state=running
List running services
systemctl list-unit-files --type=service
List all service unit files (enabled/disabled)
journalctl -u nginx
View logs for specific service
journalctl -f -u nginx
Follow service logs live
journalctl --since '1 hour ago'
Logs from last hour
systemctl daemon-reload
Reload systemd after unit file changes
systemctl cat nginx
Show unit file content
ip a
Show all network interfaces and IPs
ip route
Show routing table
ss -tulpn
Show listening ports (TCP/UDP) with process
curl -I https://example.com
HTTP HEAD request (headers only)
curl -v https://example.com
Verbose HTTP request/response
wget https://example.com/file.zip
Download file
dig example.com
DNS lookup (detailed)
dig +short example.com
DNS lookup (just IP)
ping -c 4 8.8.8.8
Test connectivity (ICMP)
nc -zv example.com 443
Test TCP port connectivity
ufw status
Check firewall status
ufw allow 8080/tcp
Allow port through firewall
ssh -L 8080:localhost:80 user@server
SSH local port forwarding
ssh -R 8080:localhost:80 user@server
SSH remote port forwarding
git init
初始化仓库
git add .
暂存所有修改
git commit -m 'msg'
提交更改
git push
推送到远程
git pull
拉取远程更新
#!/bin/bash
Shebang 指定解释器
name="DevOps"
定义变量
echo $name
引用变量
if [ $1 -gt 0 ]; then echo positive; fi
条件判断
for i in {1..5}; do echo $i; done
for 循环
func() { echo "Hello $1"; }; func World
定义函数
$0 $1 $2
脚本参数
docker run -d -p 80:80 nginx
运行 Nginx 容器
docker ps
列出运行中容器
docker images
列出本地镜像
docker build -t myapp .
构建镜像
docker exec -it container_id bash
进入容器
docker logs container_id
查看日志
docker volume create data
创建数据卷
docker network create mynet
创建网络
kubectl get nodes
查看节点
kubectl get pods -A
查看所有 Pod
kubectl create deployment nginx --image=nginx
创建 Deployment
kubectl expose deployment web --port=80 --type=NodePort
暴露服务
kubectl scale deployment web --replicas=3
扩缩容
kubectl apply -f deployment.yaml
应用 YAML
kubectl logs -f pod-name
查看日志
kubectl exec -it pod-name -- bash
进入 Pod
terraform init
初始化工作目录
terraform fmt
格式化代码
terraform validate
验证语法
terraform plan
预览变更
terraform apply tfplan
应用变更
destroy -auto-approve
销毁资源
terraform state list
查看状态
terraform output
查看输出
ansible all -i inventory.ini -m ping
检查目标机连通性
ansible-playbook site.yml
运行 Ansible 剧本
ansible-galaxy install geerlingguy.nginx
安装社区角色
ansible-doc -l
列出可用模块
ansible-vault encrypt secrets.yml
加密敏感变量文件
git checkout -b feature/ci
创建特性分支
git add .github/workflows/ci.yml
暂存工作流文件
git commit -m "feat: add CI pipeline"
提交更改
git push origin feature/ci-cd
推送分支到远程
gh run list
查看运行记录
docker run -d -p 9090:9090 prom/prometheus
启动 Prometheus
docker run -d -p 3000:3000 grafana/grafana
启动 Grafana
curl -s http://localhost:9090/metrics
测试指标端点
ss -tlnp
检查监听端口
docker run -d -p 9200:9200 -p 5601:5601 sebp/elk
启动 ELK 栈
curl -s http://localhost:9200/_cluster/health
检查 ES 集群健康
tail -f /var/log/syslog
实时查看系统日志
journalctl -u nginx --since 1h ago
查看服务日志
docker-compose up -d
启动所有服务
docker-compose ps
查看服务状态
docker-compose logs -f --tail=50 web
查看服务日志
docker-compose down
停止并移除服务
kubectl apply -f deployment.yaml
创建 K8s 资源
kubectl get pods
查看 Pod 列表
kubectl describe pod nginx
查看 Pod 详情
kubectl logs -f deployment/nginx
查看容器日志
kubectl delete -f deployment.yaml
删除 K8s 资源
helm repo add bitnami https://charts.bitnami.com/bitnami
添加 Helm 仓库
helm install my-nginx bitnami/nginx
安装 Helm 图表
helm list
查看已安装发布
helm upgrade my-nginx bitnami/nginx
升级 Helm 发布
helm uninstall my-nginx
卸载 Helm 发布
nginx -t
测试配置语法
systemctl reload nginx
重新加载 Nginx
ss -tlnp
检查监听端口
curl -I http://localhost
测试 HTTP 响应
ssh-keygen -t ed25519 -C devops@example.com
生成 SSH 密钥对
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@vps
拷贝公钥到主机
ufw allow 22/tcp
开放 SSH 端口
ufw enable
启用防火墙
fail2ban-client status
查看 fail2ban 状态
tar czf /backup/etc.tar.gz /etc
打包备份配置
rsync -avz /etc/ user@backup:/backup/
增量同步备份
mysqldump -u root -p mydb > backup.sql
导出数据库备份
scp backup.tar.gz user@offsite:/backups/
异地拷贝备份