Bash script to delete old logs

From Cramsession
Jump to navigationJump to search
✍️ Verified Author: MflavellClick to view professional profile & credentials

Computer Notes > Linux > Bash Scripts > Bash script to delete old logs


#!/bin/bash
# Directory to clean up (change this to the target directory)
TARGET_DIR="/path/to/your/directory"
# Find and delete files starting with wd_index older than 7 days
find "$TARGET_DIR" -type f -name "log_start_*" -mtime +7 -exec rm -f {} \;


deletes files in TARGET_DIR that start with log_start older than 7 days