More scripts in the library →
Check if your website is up · Bash error handling · Create dated folders · and more
Browse All Scripts →
free · no login · no fluff

Stop Googling the
Same Bash Commands

I got tired of re-searching the same bash one-liners every time I sat down at a terminal. So I started collecting them. This is that collection — real scripts, explained like a human wrote them.

Browse Snippets Try the Builder
12+Working Scripts
100%Tested on Linux
0Logins Required
FreeAlways

Copy-Paste Scripts That Work

Every snippet runs on Ubuntu, Debian, Fedora, and macOS. Tested personally. The comment at the top of each block tells you what it does before you run it.

Automated File Backup beginner
#!/bin/bash
# Copies a folder to /backup with today's timestamp.
# Run manually or schedule with cron — works either way.

SOURCE="/home/user/documents"
DEST="/backup"
DATE=$(date +%Y-%m-%d_%H-%M)

mkdir -p "$DEST"
cp -r "$SOURCE" "$DEST/backup_$DATE"
echo "Done. Saved to: backup_$DATE"
Rename All Files in a Folder intermediate
#!/bin/bash
# Renames every .txt file to .md — useful after
# exporting notes, docs, or data dumps.

for file in *.txt; do
  [ -f "$file" ] || continue
  newname="${file%.txt}.md"
  mv "$file" "$newname"
  echo "Renamed: $file → $newname"
done
Disk Space Warning beginner
#!/bin/bash
# Checks disk usage and warns if over 80%.
# Great for daily cron on a server or VPS.

THRESHOLD=80
USAGE=$(df / | awk 'NR==2{print $5}' | tr -d '%')

if [ "$USAGE" -gt "$THRESHOLD" ]; then
  echo "⚠ Disk at ${USAGE}% — time to clean up"
else
  echo "✓ Disk OK: ${USAGE}% used"
fi
Delete Old Log Files intermediate
#!/bin/bash
# Deletes .log files older than 30 days.
# Replace -delete with -print to preview first!

LOG_DIR="/var/log/myapp"
DAYS=30

find "$LOG_DIR" -type f -name "*.log" \
  -mtime +$DAYS -delete

echo "Cleaned logs older than $DAYS days"
Quick System Info Report monitor
#!/bin/bash
# Prints key stats at a glance. Alias to 'syscheck'
# in your .bashrc for fast access.

echo "=== Quick System Check ==="
echo "Host    : $(hostname)"
echo "Uptime  : $(uptime -p)"
echo "RAM     : $(free -h | awk '/Mem/{print $3"/"$2}')"
echo "Disk /  : $(df -h / | awk 'NR==2{print $3"/"$2}')"
echo "IP      : $(hostname -I | awk '{print $1}')"
echo "========================="
Create Dated Work Folder beginner
#!/bin/bash
# Creates a folder named with today's date in ~/work.
# I run this as my very first command every morning.

BASE="$HOME/work"
TODAY=$(date +%Y-%m-%d)
DIR="$BASE/$TODAY"

mkdir -p "$DIR"
echo "Ready. Working in: $DIR"
# xdg-open "$DIR"  # uncomment to open in file manager
Check If a Website Is Up monitor
#!/bin/bash
# Pings a URL and reports if it's reachable.
# Use with cron to alert you when a site goes down.

URL="https://example.com"
STATUS=$(curl -o /dev/null -s -w "%{http_code}" "$URL")

if [ "$STATUS" -eq 200 ]; then
  echo "✓ $URL is up (HTTP $STATUS)"
else
  echo "✗ $URL returned HTTP $STATUS — check it"
fi
Search Files for Text (grep) intermediate
#!/bin/bash
# Searches all .txt files in a folder for a keyword.
# Shows filename and line number for each match.

SEARCH_DIR="$HOME/documents"
KEYWORD="TODO"

echo "Searching for '$KEYWORD'..."
grep -rn "$KEYWORD" "$SEARCH_DIR" --include="*.txt"
echo "Done."
Count Lines of Code beginner
#!/bin/bash
# Counts total lines across all .py files in a project.
# Quick LOC estimate without installing any extra tools.

PROJECT_DIR="$HOME/myproject"
EXT="py"

TOTAL=$(find "$PROJECT_DIR" -name "*.$EXT" \
  | xargs wc -l 2>/dev/null \
  | tail -1 | awk '{print $1}')

echo "Total lines of .$EXT code: $TOTAL"
Find Duplicate Files advanced
#!/bin/bash
# Finds files with identical content using MD5 hashes.
# Run on Downloads folder to surface duplicates.

TARGET="$HOME/Downloads"

echo "Scanning for duplicates in $TARGET..."
find "$TARGET" -type f \
  | xargs md5sum 2>/dev/null \
  | sort \
  | awk 'seen[$1]++'
Compress Folder to .tar.gz intermediate
#!/bin/bash
# Compresses a folder into a dated .tar.gz archive.
# Smaller than .zip and native to every Linux system.

SOURCE="/home/user/project"
OUTPUT="/backup/project_$(date +%Y%m%d).tar.gz"

tar -czf "$OUTPUT" -C "$(dirname $SOURCE)" \
    "$(basename $SOURCE)"

echo "Archive created: $OUTPUT"
ls -lh "$OUTPUT"
Safe Bash Script Template best practice
#!/bin/bash
# Safe bash template — use this as your starting point
# for any script you actually care about.

set -euo pipefail  # exit on error, unset vars, pipe fails
IFS=$'\n\t'        # safer word splitting

# Your code starts here
echo "Script started at $(date)"

# ... add your logic ...

echo "Script completed successfully"

Script Builder

Not sure where to start? Pick what you want to do and this generates a working starter script. No coding required — just change the paths to match your system.

⚡ Generate a Script

Choose a task and a script generates instantly. Save as a .sh file, run chmod +x yourscript.sh, then ./yourscript.sh.

Want to Go Beyond Copy-Paste?

Resources I'd actually recommend if you want to understand bash properly. All links are free unless noted.

The Linux Command Line — Best Bash Book for Beginners

By William Shotts. Covers everything from file navigation to full scripting. Available completely free at linuxcommand.org. The best written bash resource available.

Read Free →

Practice on a Real Linux Server — $200 Free Credit

The fastest way to get good at bash is having a real Linux server to experiment on. DigitalOcean gives new users $200 in free credit for 60 days. Plenty of time to run every script on this site. (Affiliate link — we earn a small commission if you sign up)

Get $200 Free →

The Complete Linux Course — Most Popular on Udemy

Goes from zero to confident sysadmin. Covers bash, networking, permissions, users, and system administration. Usually on sale for under $15. (Affiliate link — we earn a small commission at no cost to you)

View Course →

// free tool

Crontab Guru

Visual cron schedule builder. Describe your schedule and it generates the cron syntax. I use it every time — even after years of writing cron jobs.

crontab.guru →

// free tool

ExplainShell

Paste any bash command and it breaks down every flag and argument with man page documentation. Best way to understand commands you found online.

explainshell.com →

// free course

Bash Scripting — freeCodeCamp

Full beginner bash course on YouTube. About 5 hours, covers variables, loops, functions, and real-world examples. Free, no account needed.

Watch on YouTube →

// free tool

ShellCheck

Paste any bash script and it finds bugs, bad practices, and portability issues. Like a spell-checker for shell scripts. Catches things that are hard to spot yourself.

shellcheck.net →

// community

r/bash on Reddit

Active community from beginners to experts. Good for questions when you're stuck on something specific. Friendlier than Stack Overflow for scripting questions.

reddit.com/r/bash →

// reference

GNU Bash Manual

The official, complete bash documentation. Dense but definitive — every feature, every edge case. Bookmark it and use Ctrl+F when you need the real answer.

gnu.org/bash →

Topics in the Queue

Adding new snippets regularly. Each topic gets its own set of working examples with plain-English explanations.

cron jobs deep dive string manipulation bash arrays error handling (set -e) reading user input awk one-liners sed find & replace file permissions process management ssh key automation log rotation environment variables bash functions regex in bash curl & wget scripts apt automation git automation Docker + bash

Things People Always Ask

Questions I see constantly in forums, Discord servers, and comment sections — answered as plainly as possible.

It's just a text file full of commands. The same commands you'd type in a terminal one by one — but saved in a file so the computer runs them automatically in sequence. Think of it like a recipe: you write the steps once, and the computer follows them whenever you need. The file usually ends in .sh and the very first line is always #!/bin/bash — that's the computer's way of knowing which language to use.
Two steps, and you only do step one once per file. First, make it executable: chmod +x yourscript.sh. Then run it: ./yourscript.sh. If you skip chmod, you get a "Permission denied" error — the most common beginner trip-up. You can also skip chmod entirely and type bash yourscript.sh — same result.
Nope. Linux and macOS come with bash already installed — it's been there for decades. Open a terminal and type bash --version to confirm. On Windows, install Git Bash (free, 2 minutes) or enable WSL from Windows Settings. Both give you a full bash environment at zero cost.
sh is the old minimal POSIX shell — works everywhere but has fewer features. bash is the modern version with arrays, better string handling, and more. For scripts on your own machine, always use #!/bin/bash. Only use #!/bin/sh for maximum portability — like scripts inside Docker containers where bash might not exist.
Use cron — Linux's built-in scheduler, reliable since the 1970s. Run crontab -e to open the editor, add a line like 0 2 * * * /home/you/myscript.sh to run daily at 2am. The five fields are: minute, hour, day-of-month, month, day-of-week. Confused? Use crontab.guru — free visual cron builder.
Add values after the filename when running: ./script.sh hello world. Inside the script, $1 is "hello", $2 is "world", and so on. $0 is the script name. $# is the count of arguments passed. Instead of hardcoding a folder path, accept it as $1 and the same script becomes reusable anywhere.
Common culprits: (1) Missing #!/bin/bash as the very first line. (2) Wrong path — verify with ls /your/path. (3) Windows line endings if you edited on Windows — fix with sed -i 's/\r//' yourscript.sh. (4) Add set -x right after the shebang — it prints every command before it runs so you see exactly where it breaks.
Add set -e near the top of your script. It tells bash to exit the moment any command fails. Add set -u to catch undefined variables, and set -o pipefail to catch errors inside pipes. All three together: set -euo pipefail. This is the single best habit for writing reliable scripts.
The fastest method: steal and modify. Start with scripts from this page, understand each line, change one thing at a time. For structured learning, The Linux Command Line by William Shotts is free online and the best written resource available. For video, the freeCodeCamp bash course on YouTube is solid and completely free.

Why This Exists

I've been using Linux for a while now, and I still find myself Googling the same bash commands constantly. Not because I forget them — but because I can never remember the exact syntax for the edge case I'm dealing with right now. The find command with -mtime? The awk trick to grab column five? Every. Single. Time.

Most resources out there are either too basic ("here is what echo does") or way too deep ("here is a 47-step tutorial"). There's a gap in the middle — a place for real, working scripts that handle actual everyday tasks, written in a way that someone who isn't a shell wizard can understand and modify.

So I built this. Every snippet here is something I've used in a real situation. Explanations are written how I wish someone had explained it to me. Nothing padded out for SEO. If a script is short, the explanation is short. If something has a gotcha, I call it out.

This site is updated regularly. If there's something you keep searching for and can't find here, send a note — I'll add it. For the full story, visit the About page.

More scripts in the library →
Check if your website is up · Bash error handling · Create dated folders · and more
Browse All Scripts →