Linux command to automate deletion of ‘n’ day old backup or data
Suppose if I want to keep 3 days backup with me and want to delete data before 3 days:
rm -rf `ls -lt backup_*.txt | awk '{ print $NF }' | tail -n +4`
here, ls -lt will sort by newest file at top, print $NF to select name of records and tail -n +4 will output lines starting with the 4th. In this way it will delete records older than 3 days.
If result is not found or irrelevant, Please contact us.
Submit your request