bash-linux
Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.
Author
Category
Development ToolsInstall
Hot:38
Download and extract to your skills directory
Copy command and send to OpenClaw for auto-install:
Download and install this skill https://openskills.cc/api/download?slug=sickn33-skills-bash-linux&locale=en&source=copy
Bash Linux Patterns - Terminal Commands and Script Writing Quick Reference
Skill Overview
Bash Linux Patterns is a set of Bash/Linux terminal operation guidelines designed for developers, covering common commands, pipe operations, error handling, and script writing patterns to help you work efficiently on macOS or Linux systems.
Applicable Scenarios
1. Server Operations and System Administration
When you need to remotely log into servers for system maintenance, this skill set provides core commands for process management, port occupancy queries, and log file tailing, allowing you to quickly locate and resolve system issues.
2. Automated Script Development
When writing deployment scripts, data processing scripts, or system monitoring scripts, it provides complete script templates, error handling patterns, and variable management methods to help you create robust and maintainable Shell scripts.
3. Daily Development Workflow
In a local development environment, for tasks like file searching, text processing, and dependency installation, these command patterns can greatly improve your productivity, especially when using macOS or Linux as your development environment.
Core Features
1. Command Chaining and Pipes
Master the meanings and use cases of operators like
&&, ||, and ;, as well as the text-stream processing power of the pipe |. For example, npm install && npm run dev ensures the service only starts after a successful install, and ls | grep ".js" quickly filters files.2. File and Text Processing Toolset
Includes quick-reference usages for common tools like
find for locating files, grep for searching content, sed for text replacement, awk for field extraction, and sort/uniq for deduplication and counting—covering 90% of text processing needs in daily development.3. Process Management and Network Operations
Provides
ps, lsof, kill and other process management commands, as well as usage of the curl network request tool, helping you quickly troubleshoot port usage, terminate zombie processes, and test API endpoints.Frequently Asked Questions
What is the difference between Bash and PowerShell?
Bash is a text-stream-based shell, while PowerShell is object-based. Bash uses
$VAR to access variables; PowerShell uses $env:VAR for environment variables. Bash pipes pass plain text, whereas PowerShell passes structured objects. For cross-platform development, Bash is the common choice on macOS and Linux.How do you handle errors in scripts?
Add
set -euo pipefail at the start of a script to enable strict mode: -e exits on error, -u errors on use of undefined variables, and -o pipefail causes the pipeline to fail if any command fails. You can also use trap to define cleanup functions to ensure resources are released if the script exits unexpectedly.What are grep, sed, and awk used for respectively?
grep is used for searching and filtering text and is suited for finding lines that contain specific patterns; sed is used for text replacement and editing, suitable for bulk modifying file contents; awk is used for structured data processing, ideal for extracting columns and formatting output. The three are often used together in text-processing pipelines.How do you find and terminate the process occupying a port?
Use
lsof -i :<port> to see the process occupying that port, then use kill -9 $(lsof -t -i :<port>) to terminate it in one command. For example, to clear port 3000: kill -9 $(lsof -t -i :3000).How do you set environment variables?
For a temporary setting, use
export VAR="value", which is only valid for the current session. To set it permanently, add it to your ~/.bashrc or ~/.zshrc configuration file. In scripts, you can set an environment variable for a single command with the form VAR="value" command.