跳转到内容

Linux 命令速查

Debian / Ubuntu 上 update 只刷新索引,真正升级要跟上 upgrade

终端窗口
sudo apt update
sudo apt upgrade -y
# Remove packages that nothing depends on anymore
sudo apt autoremove --purge -y
终端窗口
# Status, with the last few log lines
systemctl status nginx
# Start now and enable on boot in one go
sudo systemctl enable --now nginx
# Reload unit files after editing them
sudo systemctl daemon-reload

查日志跟着服务走,-f 持续跟随,-n 限制行数:

终端窗口
journalctl -u nginx -n 100 -f

磁盘写满时按这个顺序查:先看整体,再定位到具体目录。

终端窗口
# Overall usage, human readable
df -h
# Largest entries in the current directory
du -h --max-depth=1 . | sort -h | tail -20
终端窗口
sudo ufw status verbose
sudo ufw allow OpenSSH
sudo ufw enable
终端窗口
# Listening sockets with the owning process
sudo ss -tulpn
# Find a process by name
pgrep -a node

从 GitHub Releases 下载 deb 包并用 apt 安装,apt 会自动补齐依赖。换版本时只改 URL 里的版本号。

终端窗口
wget https://github.com/Clash-Verge-rev/clash-verge-rev/releases/download/v2.5.2/Clash.Verge_2.5.2_amd64.deb \
-O /tmp/clash-verge.deb && \
sudo apt install -y /tmp/clash-verge.deb

上面那条只装程序本体。装完还要开 TUN、改设置、加直连规则、导订阅,这些 clash.sh 都包了。 它必须带子命令,不带参数只会打印用法:

终端窗口
# 全流程:install -> settings -> rules -> sub -> check
CLASH_SUB_URL='https://你的订阅地址' curl -fsSL https://759705.cc/clash.sh | sh -s -- all
# 也可以单独跑某一步
curl -fsSL https://759705.cc/clash.sh | sh -s -- install
curl -fsSL https://759705.cc/clash.sh | sh -s -- check
子命令 做什么
install dpkg --print-architecture 选 amd64/arm64 包,apt 安装,然后装 clash-verge-service——TUN 要靠这个 root 服务拿 CAP_NET_ADMIN
settings 改写 verge.yaml 的 20 个键,写入 dns_config.yaml 并打开 enable_dns_settings
rules 把直连规则装进全局脚本增强 profiles/Script.js,对所有订阅生效
sub CLASH_SUB_URL,先把 app 拉起来再投递 clash:// 深链
check 打印 PASS/FAIL/SKIP 体检表,有 FAIL 时退出码为 1

几个必须知道的前提:

  • settings 要求 app 已退出。 app 运行时会用内存态覆写 verge.yaml,这时候改文件等于白改。 脚本检测到进程会直接拒绝;想让它替你关掉就加 CLASH_FORCE_STOP=1
  • TUN 依赖服务。 没装 clash-verge-service 时,app 启动会把 enable_tun_mode 强制改回 false。 所以 settings 检测不到服务就如实写 false,不会写一个看着生效实际会被打回的 true
  • 规则走脚本增强,不是 Merge.yaml merge 是纯深合并,在里面写 rules:整段替换订阅自带的规则; prepend-rules 这个键在上游只存在于单元测试里,没有实现。全局 Script.js 才能真正前插。
  • 订阅地址是机密。 只经环境变量传入,不写进任何文件,打印时只保留协议和域名。
终端窗口
# 预览:只打印将要执行的命令,不下载也不改任何文件
HUB_DRY_RUN=1 curl -fsSL https://759705.cc/clash.sh | sh -s -- all
# 固定版本,不取 latest
CLASH_VERGE_VERSION=2.5.2 curl -fsSL https://759705.cc/clash.sh | sh -s -- install

控制接口在 unix socket 上,不是 127.0.0.1:9097——TCP 外部控制器默认是关的, config.yaml 里那个 9097 是兜底写回的值,不代表真在监听。socket 上不需要鉴权头:

终端窗口
SOCK=/tmp/verge/verge-mihomo.sock
curl -s --unix-socket "$SOCK" http://localhost/version
curl -s --unix-socket "$SOCK" http://localhost/configs
# 出口是否真的通
curl -sS -o /dev/null -w '%{http_code}\n' -m 10 -x http://127.0.0.1:7897 \
https://cp.cloudflare.com/generate_204 # 期望 204
# TUN 服务状态
systemctl is-active clash-verge-service && test -S /tmp/verge/clash-verge-service.sock && echo ok

配置文件都在 ~/.local/share/io.github.clash-verge-rev.clash-verge-rev/, 其中 clash-verge.yaml 是真正下发给内核的合并产物,config.yaml 不是。