Preview a retention policy
Produce a retention plan without deleting the files it describes.
Selection and deletion are different operations
A retention rule can be reviewed safely as a plan before it changes anything. Describe which paths would be retained or removed and why. An age-based selection is not permission to delete every matching file immediately, especially when another process may still be using one.
The collector supplies integer age_days values at a known collection time. This avoids differences between GNU and BSD date or stat commands and makes the exercise reproducible. In this teaching policy, unprotected files aged 30 days or more are expired. Exactly 30 is included; a protected file is retained regardless of age.
Give safeguards precedence
Check the protected flag before the age threshold. A row meeting both conditions should have reason protected, not expired. The reasons are part of the report contract and help a reviewer understand what would happen before any later apply step.
All paths in this exercise refer to virtual files, and the script must leave them unchanged. The lab checks their content as well as the plan. In a real cleanup tool, the execution phase would need additional controls for path scope, races, symlinks and recovery. A small deterministic plan is a useful first step toward that more demanding tool.
awk -F '\t' 'NR>1 {printf "%s is %s days old\n",$1,$2}' retention.tsv
Put it into practice.
retention.tsv has validated unique path<TAB>age_days<TAB>protected rows; age is a nonnegative integer and protected is yes or no. Print path<TAB>decision<TAB>reason sorted by path in LC_ALL=C order. Protected files are keep/protected regardless of age. Other files aged at least 30 days are remove/expired; younger files are keep/recent. This is only a plan: never remove or modify the listed files.
See an explained solution
export LC_ALL=C
printf 'path\tdecision\treason\n'
awk -F '\t' 'NR>1 {if($3=="yes"){decision="keep";reason="protected"}else if($2>=30){decision="remove";reason="expired"}else{decision="keep";reason="recent"}printf "%s\t%s\t%s\n",$1,decision,reason}' retention.tsv | sort
The protected condition takes precedence over age, so safeguards remain visible in the plan. Sorting and explicit reasons make the proposed action reviewable while filesystem assertions prove that the exercise does not perform deletion.