#!/bin/bash find /data/logs -maxdepth 5 -name ".tmp" -type f -mtime +0 -delete find…
- User
#!/bin/bash find /data/logs -maxdepth 5 -name ".tmp" -type f -mtime +0 -delete find /data/logs -maxdepth 5 -name ".zip" -type f -mtime +2 -delete find /data/logs -maxdepth 5 -name ".tar.gz" -type f -mtime +2 -delete find /data/logs -maxdepth 5 -name ".gz" -type f -mtime +2 -delete find /data/logs -maxdepth 5 -name ".log" -type f -mtime +2 -delete find /data/logs -maxdepth 5 -name ".jsonl" -type f -mtime +2 -delete find /data/logs -maxdepth 5 -name "gc.log." -type f -mtime +0 -delete find /data/logs -maxdepth 5 -name "catalina.out." -type f -mtime +0 -delete
- Assistant
Explanation:
This script uses the 'find' command to search for files in the '/data/logs' directory that match specific criteria and delete them. Here's what each line does:
- Find and delete all files ending in '.tmp' that are at most one day old (using the '-mtime' option with a value of '+0', which means "modified more than 0 days ago").
- Find and delete all files ending in '.zip' that are more than two days old.
- Find and delete all files ending in '.tar.gz' that are more than two days old.
- Find and delete all files ending in '.gz' that are more than two days old.
- Find and delete all files ending in '.log' that are more than two days old.
- Find and delete all files ending in '.jsonl' that are more than two days old.
- Find and delete all files starting with 'gc.log.' that are at most one day old.
- Find and delete all files starting with 'catalina.out.' that are at most one day old.
Note that the '-maxdepth' option is used to limit the search depth to 5 levels (i.e. subdirectories), which helps prevent accidentally deleting files in unintended locations. Also, the '-type f' option is used to only match files (not directories or other types of files).