bash-linux
Original:🇺🇸 English
Translated
Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.
2installs
Added on
NPX Install
npx skill4agent add davila7/claude-code-templates bash-linuxTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Bash Linux Patterns
Essential patterns for Bash on Linux/macOS.
1. Operator Syntax
Chaining Commands
| Operator | Meaning | Example |
|---|---|---|
| Run sequentially | |
| Run if previous succeeded | |
| Run if previous failed | |
| Pipe output | |
2. File Operations
Essential Commands
| Task | Command |
|---|---|
| List all | |
| Find files | |
| File content | |
| First N lines | |
| Last N lines | |
| Follow log | |
| Search in files | |
| File size | |
| Disk usage | |
3. Process Management
| Task | Command |
|---|---|
| List processes | |
| Find by name | |
| Kill by PID | |
| Find port user | |
| Kill port | |
| Background | |
| Jobs | |
| Bring to front | |
4. Text Processing
Core Tools
| Tool | Purpose | Example |
|---|---|---|
| Search | |
| Replace | |
| Extract columns | |
| Cut fields | |
| Sort lines | |
| Unique lines | |
| Count | |
5. Environment Variables
| Task | Command |
|---|---|
| View all | |
| View one | |
| Set temporary | |
| Set in script | |
| Add to PATH | |
6. Network
| Task | Command |
|---|---|
| Download | |
| API request | |
| POST JSON | |
| Check port | |
| Network info | |
7. Script Template
bash
#!/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 "$@"8. Common Patterns
Check if command exists
bash
if command -v node &> /dev/null; then
echo "Node is installed"
fiDefault variable value
bash
NAME=${1:-"default_value"}Read file line by line
bash
while IFS= read -r line; do
echo "$line"
done < file.txtLoop over files
bash
for file in *.js; do
echo "Processing $file"
done9. Differences from PowerShell
| Task | PowerShell | Bash |
|---|---|---|
| List files | | |
| Find files | | |
| Environment | | |
| String concat | | |
| Null check | | |
| Pipeline | Object-based | Text-based |
10. Error Handling
Set options
bash
set -e # Exit on error
set -u # Exit on undefined variable
set -o pipefail # Exit on pipe failure
set -x # Debug: print commandsTrap for cleanup
bash
cleanup() {
echo "Cleaning up..."
rm -f /tmp/tempfile
}
trap cleanup EXITRemember: Bash is text-based. Usefor success chains,&&for safety, and quote your variables!set -e