bash-linux by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --skill bash-linux适用于 Linux/macOS 的 Bash 核心模式。
| 操作符 | 含义 | 示例 |
|---|---|---|
; | 顺序执行 | cmd1; cmd2 |
&& | 前一个命令成功则执行 | npm install && npm run dev |
| ` | ` | |
| ` | ` |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 管道输出 |
| 任务 | 命令 |
|---|---|
| 列出所有文件 | ls -la |
| 查找文件 | find . -name "*.js" -type f |
| 查看文件内容 | cat file.txt |
| 查看前 N 行 | head -n 20 file.txt |
| 查看后 N 行 | tail -n 20 file.txt |
| 跟踪日志 | tail -f log.txt |
| 在文件中搜索 | grep -r "pattern" --include="*.js" |
| 文件大小 | du -sh * |
| 磁盘使用情况 | df -h |
| 任务 | 命令 |
|---|---|
| 列出进程 | ps aux |
| 按名称查找 | `ps aux |
| 通过 PID 终止 | kill -9 <PID> |
| 查找端口使用者 | lsof -i :3000 |
| 终止端口进程 | kill -9 $(lsof -t -i :3000) |
| 后台运行 | npm run dev & |
| 查看后台任务 | jobs -l |
| 切换到前台 | fg %1 |
| 工具 | 用途 | 示例 |
|---|---|---|
grep | 搜索 | grep -rn "TODO" src/ |
sed | 替换 | sed -i 's/old/new/g' file.txt |
awk | 提取列 | awk '{print $1}' file.txt |
cut | 切割字段 | cut -d',' -f1 data.csv |
sort | 排序行 | sort -u file.txt |
uniq | 去重行 | `sort file.txt |
wc | 计数 | wc -l file.txt |
| 任务 | 命令 |
|---|---|
| 查看所有 | env 或 printenv |
| 查看单个 | echo $PATH |
| 临时设置 | export VAR="value" |
| 在脚本中设置 | VAR="value" command |
| 添加到 PATH | export PATH="$PATH:/new/path" |
| 任务 | 命令 |
|---|---|
| 下载 | curl -O https://example.com/file |
| API 请求 | curl -X GET https://api.example.com |
| POST JSON | curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL |
| 检查端口 | nc -zv localhost 3000 |
| 网络信息 | ifconfig 或 ip addr |
#!/bin/bash
set -euo pipefail # Exit on error, undefined var, pipe fail
# Colors (optional)
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Functions
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
# Main
main() {
log_info "Starting..."
# Your logic here
log_info "Done!"
}
main "$@"
if command -v node &> /dev/null; then
echo "Node is installed"
fi
NAME=${1:-"default_value"}
while IFS= read -r line; do
echo "$line"
done < file.txt
for file in *.js; do
echo "Processing $file"
done
| 任务 | PowerShell | Bash |
|---|---|---|
| 列出文件 | Get-ChildItem | ls -la |
| 查找文件 | Get-ChildItem -Recurse | find . -type f |
| 环境变量 | $env:VAR | $VAR |
| 字符串连接 | "$a$b" | "$a$b" (相同) |
| 空值检查 | if ($x) | if [ -n "$x" ] |
| 管道 | 基于对象 | 基于文本 |
set -e # Exit on error
set -u # Exit on undefined variable
set -o pipefail # Exit on pipe failure
set -x # Debug: print commands
cleanup() {
echo "Cleaning up..."
rm -f /tmp/tempfile
}
trap cleanup EXIT
记住: Bash 是基于文本的。使用
&&处理成功链,set -e保证安全,并对变量使用引号!
每周安装量
187
代码仓库
GitHub 星标数
22.6K
首次出现
2026年1月25日
安全审计
安装于
opencode149
claude-code146
gemini-cli140
codex134
github-copilot131
cursor123
Essential patterns for Bash on Linux/macOS.
| Operator | Meaning | Example |
|---|---|---|
; | Run sequentially | cmd1; cmd2 |
&& | Run if previous succeeded | npm install && npm run dev |
| ` | ` | |
| ` | ` | Pipe output |
| Task | Command |
|---|---|
| List all | ls -la |
| Find files | find . -name "*.js" -type f |
| File content | cat file.txt |
| First N lines | head -n 20 file.txt |
| Last N lines | tail -n 20 file.txt |
| Follow log | tail -f log.txt |
| Task | Command |
|---|---|
| List processes | ps aux |
| Find by name | `ps aux |
| Kill by PID | kill -9 <PID> |
| Find port user | lsof -i :3000 |
| Kill port | kill -9 $(lsof -t -i :3000) |
| Background | npm run dev & |
| Jobs | jobs -l |
| Tool | Purpose | Example |
|---|---|---|
grep | Search | grep -rn "TODO" src/ |
sed | Replace | sed -i 's/old/new/g' file.txt |
awk | Extract columns | awk '{print $1}' file.txt |
cut |
| Task | Command |
|---|---|
| View all | env or printenv |
| View one | echo $PATH |
| Set temporary | export VAR="value" |
| Set in script | VAR="value" command |
| Add to PATH | export PATH="$PATH:/new/path" |
| Task | Command |
|---|---|
| Download | curl -O https://example.com/file |
| API request | curl -X GET https://api.example.com |
| POST JSON | curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL |
| Check port | nc -zv localhost 3000 |
| Network info | ifconfig or ip addr |
#!/bin/bash
set -euo pipefail # Exit on error, undefined var, pipe fail
# Colors (optional)
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Functions
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
# Main
main() {
log_info "Starting..."
# Your logic here
log_info "Done!"
}
main "$@"
if command -v node &> /dev/null; then
echo "Node is installed"
fi
NAME=${1:-"default_value"}
while IFS= read -r line; do
echo "$line"
done < file.txt
for file in *.js; do
echo "Processing $file"
done
| Task | PowerShell | Bash |
|---|---|---|
| List files | Get-ChildItem | ls -la |
| Find files | Get-ChildItem -Recurse | find . -type f |
| Environment | $env:VAR | $VAR |
| String concat | "$a$b" |
set -e # Exit on error
set -u # Exit on undefined variable
set -o pipefail # Exit on pipe failure
set -x # Debug: print commands
cleanup() {
echo "Cleaning up..."
rm -f /tmp/tempfile
}
trap cleanup EXIT
Remember: Bash is text-based. Use
&&for success chains,set -efor safety, and quote your variables!
Weekly Installs
187
Repository
GitHub Stars
22.6K
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode149
claude-code146
gemini-cli140
codex134
github-copilot131
cursor123
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
114,200 周安装
| Search in files | grep -r "pattern" --include="*.js" |
| File size | du -sh * |
| Disk usage | df -h |
| Bring to front | fg %1 |
| Cut fields |
cut -d',' -f1 data.csv |
sort | Sort lines | sort -u file.txt |
uniq | Unique lines | `sort file.txt |
wc | Count | wc -l file.txt |
"$a$b" (same) |
| Null check | if ($x) | if [ -n "$x" ] |
| Pipeline | Object-based | Text-based |