Bash script to delete old logs: Difference between revisions

From Cramsession
Jump to navigationJump to search
✍️ Verified Author: MflavellClick to view professional profile & credentials
No edit summary
No edit summary
 
Line 1: Line 1:
[[Computer Notes]] > [[Linux]] > [[Bash Scripts]] > Bash script to delete old logs


  #!/bin/bash
  #!/bin/bash

Latest revision as of 21:24, 12 December 2025

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