Cloudkul Support

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.

Is this article is helpful?

People like and 0 people dislike.

If result is not found or irrelevant, Please contact us.

Submit your request