Bash script to delete old logs: Difference between revisions

From Cramsession
Jump to navigationJump to search
✍️ Verified Author: MflavellClick to view professional profile & credentials
(Created page with " #!/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")
 
No edit summary
Line 1: Line 1:


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

Revision as of 21:24, 12 December 2025

#!/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