2.0 KiB
2.0 KiB
name, description
| name | description |
|---|---|
| bash-linux | 当需要在 Linux/macOS Bash 环境或容器内查文件、搜文本、跑脚本、看日志、处理进程、使用管道、环境变量或编写小型 shell 命令时使用。它是辅助命令行规范,不属于 SQL 业务流水线。 |
Bash Linux(命令行规范)
目标
让 agent 在 Bash/Linux/容器环境下用稳定、可解释、低风险的方式执行命令。先观察,再操作;先缩小范围,再修改。
基本原则
- 查文件优先用
rg --files,不可用时用find。 - 搜内容优先用
rg -n。 - 读文件用
sed -n、head、tail控制输出量。 - 脚本使用
set -euo pipefail。 - 路径和变量要加引号。
- 删除、移动、改权限前必须确认目标范围。
- 长日志只摘关键部分,不整屏倾倒。
- 容器内的
127.0.0.1指向容器自己,不等于宿主机。
常用命令
pwd
ls -la
find . -type f -name '*.py'
rg -n "keyword" .
sed -n '1,120p' file.txt
head -n 40 file.txt
tail -n 100 app.log
wc -l file.txt
Docker/容器排查
docker ps
docker logs --tail 100 <container>
docker exec -it <container> sh
getent hosts host.docker.internal
curl -fsS http://host.docker.internal:8000/health
进程和端口
ps aux | grep '[p]ython'
lsof -i :8000
kill <pid>
脚本模板
#!/usr/bin/env bash
set -euo pipefail
main() {
if [ "$#" -lt 1 ]; then
echo "usage: $0 <arg>" >&2
exit 2
fi
echo "arg=$1"
}
main "$@"
输出报告
command_report:
purpose: "为什么运行"
command: "命令摘要"
result: success | failed | skipped
important_output: "关键输出"
next_step: "下一步"
禁止行为
- 不要对未确认路径执行递归删除。
- 不要把不可信文件名直接拼进危险命令。
- 不要默认 GNU 命令参数在 macOS 上一定可用。
- 不要留下用户不需要的后台进程。
- 不要在没确认网络边界时把容器 localhost 当宿主机。