New paste Use cases Explore public pastes Text tools Developer API The Paste Library Security Sign in with Google
BASHExample pasteCreated 2026-08-022 viewsNo expiry

Bash: Archive logs older than seven days

Raw New paste
bashRead-only
1
#!/usr/bin/env bash
set -euo pipefail

log_dir="${1:-./logs}"
archive_dir="${2:-./archive}"
mkdir -p "$archive_dir"

find "$log_dir" -type f -name '*.log' -mtime +7 -print0 |
  while IFS= read -r -d '' file; do
    gzip -c "$file" > "$archive_dir/$(basename "$file").gz"
    rm "$file"
  done
Report abuse

Paste details

Visibility
Public
Size
292 bytes
Protection
Standard link access
Retention
No automatic expiry

Share with confidence

Unlisted links are not searchable, but anyone with the URL can open them. Never paste live credentials or personal data.