Explore Bash scripting mastery with our comprehensive repository. From beginner basics to advanced techniques, dive into practical examples and expert guides for efficient automation. Dive into practical examples and guides to enhance automation skills and streamline workflows efficiently.
git clone https://github.com/king04aman/Bash-Scripting-Cheatsheet.gitThe Bash Scripting Cheat Sheet is a comprehensive reference repository for learning and mastering Bash scripting across Unix/Linux environments. It covers essential concepts including variables, control structures (if statements, loops, case statements), functions, file operations, and text processing with tools like sed and awk. The resource includes practical examples for system administration tasks such as monitoring CPU and disk usage, managing network connectivity, backing up files, and generating passwords. Designed for both beginners and experienced developers, it provides quick-reference guides for command-line arguments, I/O redirectors, debugging techniques, and best practices for efficient shell script automation.
["Identify the specific task you want to automate (e.g., file backups, log rotation, system monitoring).","Replace [TASK], [CONTEXT], [INPUTS], [OPERATIONS], and [OUTPUT_DESTINATION] in the prompt template with your specific requirements.","Test the generated script in a safe environment (e.g., a test directory or virtual machine) before deploying to production.","Use `chmod +x script.sh` to make the script executable after generating it.","Run the script with appropriate arguments and monitor the output and log files for verification.","For complex scripts, consider adding error handling for additional edge cases and validate input paths thoroughly."]
Learning Bash scripting fundamentals and advanced syntax
System monitoring and administration automation
File backup and compression operations
Text processing and file manipulation
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/king04aman/Bash-Scripting-CheatsheetCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Generate a Bash script that automates [TASK] in [CONTEXT]. The script should handle [INPUTS], perform [OPERATIONS], and output results to [OUTPUT_DESTINATION]. Include error handling for [COMMON_ERRORS] and logging to [LOG_FILE]. Example: 'Generate a Bash script to back up a directory to a remote server using rsync. The script should accept source and destination paths as arguments, handle permission errors, and log operations to /var/log/backup.log.'
```bash
#!/bin/bash
# Backup Script for Critical Directories
# Usage: ./backup_script.sh /path/to/source /path/to/destination
# Validate arguments
if [ "$#" -ne 2 ]; then
echo "Error: Invalid number of arguments. Usage: $0 <source_dir> <destination_dir>" >&2
exit 1
fi
SOURCE_DIR="$1"
DEST_DIR="$2"
LOG_FILE="/var/log/directory_backup.log"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
# Create log directory if it doesn't exist
mkdir -p "$(dirname "$LOG_FILE")"
# Check if source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
echo "[$TIMESTAMP] ERROR: Source directory $SOURCE_DIR does not exist" >> "$LOG_FILE"
exit 1
fi
# Check if destination directory exists, create if not
if [ ! -d "$DEST_DIR" ]; then
echo "[$TIMESTAMP] INFO: Creating destination directory $DEST_DIR" >> "$LOG_FILE"
mkdir -p "$DEST_DIR"
fi
# Perform backup using rsync with compression and archive mode
if rsync -avz --delete "$SOURCE_DIR/" "$DEST_DIR/"; then
echo "[$TIMESTAMP] SUCCESS: Backup completed from $SOURCE_DIR to $DEST_DIR" >> "$LOG_FILE"
echo "Backup completed successfully. Files transferred: $(rsync -avz --delete "$SOURCE_DIR/" "$DEST_DIR/" --dry-run | grep -c '^deleting')"
else
echo "[$TIMESTAMP] ERROR: Backup failed from $SOURCE_DIR to $DEST_DIR" >> "$LOG_FILE"
exit 1
fi
echo "Backup operation completed at $TIMESTAMP"
```
**Example Execution:**
```
$ ./backup_script.sh /home/user/documents /mnt/backup/documents
Backup completed successfully. Files transferred: 42
```
**Log Output:**
```
[2023-11-15 14:30:45] INFO: Creating destination directory /mnt/backup/documents
[2023-11-15 14:30:47] SUCCESS: Backup completed from /home/user/documents to /mnt/backup/documents
```Automate your browser workflows effortlessly
Secure bash execution for AI agents
Get more done every day with Microsoft Teams – powered by AI
Automate your spreadsheet tasks with AI power
Agentic AI Workflow platform
Connected workspace for docs, wikis, and projects
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan