Skill

Master Bash Linux Command Patterns

Bash/Linux reference skill covering command chaining, file/process/text tools, a script template, and error-handling patterns.


74
Spark score
out of 100
Updated 18 days ago
Version 14.2.0

Add to Favorites

Why it matters

Streamline your Linux and macOS command-line operations with essential Bash patterns. This asset provides a comprehensive guide to operator syntax, file and process management, text manipulation, environment variables, and networking commands.

Outcomes

What it gets done

01

Execute sequential and conditional command chains.

02

Perform common file operations like listing, finding, and searching.

03

Manage processes, including finding, killing, and backgrounding.

04

Utilize text processing tools like grep, sed, and awk.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-bash-linux | bash

Overview

Bash Linux Patterns

A Bash/Linux reference skill covering command chaining, file/process/text-processing commands, a strict-mode script scaffold, and error-handling patterns. Use when writing or debugging Bash scripts and command-line workflows on Linux/macOS.

What it does

Bash Linux Patterns is a reference skill for essential Bash commands and idioms on Linux/macOS, spanning ten areas: operator syntax for chaining commands (; sequential, && run-on-success, || run-on-failure, | pipe), file operations (ls -la, find -name -type f, cat, head/tail, tail -f for following logs, grep -r, du -sh, df -h), process management (ps aux, kill -9 <PID>, lsof -i :PORT to find and kill a port's owner, backgrounding with &, jobs -l, fg), and text processing (grep, sed -i for in-place replace, awk for column extraction, cut -d, sort -u, uniq -c, wc -l).

When to use - and when NOT to

Use it when writing or debugging shell scripts and command-line workflows on Linux/macOS - environment variable handling (env/printenv, export VAR="value", appending to PATH), networking (curl -O to download, curl -X POST with a JSON body, nc -zv to check a port, ifconfig/ip addr), and a dedicated comparison table mapping PowerShell equivalents to Bash (Get-ChildItem to ls -la, $env:VAR to $VAR, object-based pipelines to text-based ones, if ($x) to if [ -n "$x" ]). It is not a PowerShell reference itself - that table exists only to orient users coming from PowerShell.

Inputs and outputs

The skill provides a reusable script scaffold combining strict-mode error handling, colored logging, and a main entry point:

#!/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 "$@"

Common idioms covered on top of this: checking whether a command exists (command -v node &> /dev/null), defaulting an unset variable (NAME=${1:-"default_value"}), reading a file line by line with while IFS= read -r line, and looping over matching files with for file in *.js.

Integrations

Error-handling options are broken out individually - set -e (exit on error), set -u (exit on undefined variable), set -o pipefail (exit on pipe failure), and set -x (debug: print each command) - plus a trap cleanup EXIT pattern for guaranteed cleanup on script exit, regardless of how the script terminates.

Who it's for

Developers writing Bash scripts or working the Linux/macOS command line who want a quick, reliable reference for command chaining, file/process/text-processing commands, safe script scaffolding, and common idioms rather than looking each one up individually.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.