Bash script to delete old logs: Difference between revisions
From Cramsession
Jump to navigationJump to search
✍️ Verified Author: Mflavell • Click 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 |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Computer Notes]] > [[Linux]] > [[Bash Scripts]] > Bash script to delete old logs | |||
#!/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 {} \; | ||
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