Skip to content

Instantly share code, notes, and snippets.

@yazanmonshed
Last active May 5, 2024 09:09
Show Gist options
  • Save yazanmonshed/a0be6cc7a565c8f5fa06c5593d9b7d6e to your computer and use it in GitHub Desktop.
Save yazanmonshed/a0be6cc7a565c8f5fa06c5593d9b7d6e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Set the path to the Laravel logs directory
LOG_DIR=/path/to/laravel/logs
# Set the number of days to keep log files
DAYS_TO_KEEP=7
# Find all Laravel log files older than $DAYS_TO_KEEP days and delete them
find "$LOG_DIR" -name "*.log" -type f -mtime +$DAYS_TO_KEEP -exec rm {} \;
# Output a message indicating the number of files deleted
echo "Deleted $(find "$LOG_DIR" -name "*.log" -type f -mtime +$DAYS_TO_KEEP | wc -l) log files older than $DAYS_TO_KEEP days."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment