3 snippets

Bash/Shell Snippets

Shell scripting snippets for automation and DevOps.

files

Find files by pattern

Search for files using find and grep.

# Find files by name
find . -name "*.ts" -type f

# Find and delete
find . -name "*.log" -delete

# Find files modified in last 24h
find . -mtime -1 -type f

# Search content (recursive grep)
grep -rn "TODO" --include="*.ts" .

# Find large files (>100MB)
find . -size +100M -type f

text

Text processing one-liners

Process and transform text with sed, awk, and friends.

# Count lines in file
wc -l file.txt

# Sort and count unique lines
sort file.txt | uniq -c | sort -rn

# Replace text in file (in-place)
sed -i '' 's/old/new/g' file.txt

# Print specific column
awk '{print $2}' file.txt

# Extract emails
grep -oE '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' file.txt

# CSV to TSV
sed 's/,/\t/g' file.csv > file.tsv

git

Git shortcuts and aliases

Useful Git commands and aliases for daily development.

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Amend last commit
git commit --amend --no-edit

# Interactive rebase (last 3 commits)
git rebase -i HEAD~3

# Stash with message
git stash push -m "work in progress"

# Delete merged branches
git branch --merged | grep -v main | xargs git branch -d

# Set useful aliases
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.st status
git config --global alias.lg "log --oneline --graph --all"
All Languages